diff options
| author | Lexi Winter <lexi@le-fay.org> | 2025-07-01 22:02:48 +0100 |
|---|---|---|
| committer | Lexi Winter <lexi@le-fay.org> | 2025-07-01 22:02:48 +0100 |
| commit | 47999457e647352ae7e71d43c65e7b39ae5ca567 (patch) | |
| tree | 7e5411fdacb357080db892058173879665238981 /nihil.cli/command_tree.ccm | |
| parent | 762fdfaa953b35ed4c402c74890c5c30155a5dab (diff) | |
| download | nihil-47999457e647352ae7e71d43c65e7b39ae5ca567.tar.gz nihil-47999457e647352ae7e71d43c65e7b39ae5ca567.tar.bz2 | |
cli: add tests for command_tree
Diffstat (limited to 'nihil.cli/command_tree.ccm')
| -rw-r--r-- | nihil.cli/command_tree.ccm | 16 |
1 files changed, 7 insertions, 9 deletions
diff --git a/nihil.cli/command_tree.ccm b/nihil.cli/command_tree.ccm index 6cfabe9..7399357 100644 --- a/nihil.cli/command_tree.ccm +++ b/nihil.cli/command_tree.ccm @@ -120,18 +120,15 @@ private: }; // The command tree stores commands in a tree structure suitable for searching. -struct command_tree +export struct command_tree { // Add a node to the tree. Returns false if the node already exists. - auto insert(this command_tree &self, std::ranges::range auto &&path, - std::shared_ptr<command> command) -> void - requires(std::constructible_from<std::string_view, - std::ranges::range_value_t<decltype(path)>>) + auto insert(this command_tree &self, std::shared_ptr<command> command) -> void { auto *this_node = &self.m_root_node; // Find the node for this key. - for (auto &&this_word : path) + for (auto &&this_word : command->path() | std::views::split(' ')) this_node = this_node->get_or_create_child(std::string_view(this_word)); // Set the new value. @@ -143,7 +140,7 @@ struct command_tree requires(std::constructible_from<std::string_view, std::ranges::range_value_t<decltype(args)>>) { - auto const *this_node = &self.m_root_node; + auto *this_node = &self.m_root_node; auto rest = args | std::views::take_while([&](auto &&str) { @@ -169,9 +166,10 @@ private: { auto tree = command_tree(); - for (auto &&command : get_registered_commands()) + for (auto &&command : get_registered_commands()) { // Throws std::logic_error on duplicates. - tree.insert(command->path() | std::views::split(' '), command); + tree.insert(command); + } return tree; } |
