diff options
| author | Lexi Winter <lexi@le-fay.org> | 2025-06-27 13:23:47 +0100 |
|---|---|---|
| committer | Lexi Winter <lexi@le-fay.org> | 2025-06-27 13:23:47 +0100 |
| commit | 35ff96b08ef09dc91005472b5ea88b4acdf40041 (patch) | |
| tree | d3de7ce243ab33794cae86f9fd410c648897c169 | |
| parent | 187e18021aad8e32d59d04e7769424a6becd86cf (diff) | |
| download | nihil-35ff96b08ef09dc91005472b5ea88b4acdf40041.tar.gz nihil-35ff96b08ef09dc91005472b5ea88b4acdf40041.tar.bz2 | |
nihil: fix command_map registration
| -rw-r--r-- | nihil/command_map.cc | 2 | ||||
| -rw-r--r-- | nihil/command_map.ccm | 13 |
2 files changed, 9 insertions, 6 deletions
diff --git a/nihil/command_map.cc b/nihil/command_map.cc index fc31c87..f5353e0 100644 --- a/nihil/command_map.cc +++ b/nihil/command_map.cc @@ -146,7 +146,7 @@ struct command_tree { -> std::optional<command> { auto *this_node = &self._root_node; -{} + // Find the node for this key. for (auto &&next : path) { this_node = this_node->get_child(next); diff --git a/nihil/command_map.ccm b/nihil/command_map.ccm index 5c60639..3c58ecc 100644 --- a/nihil/command_map.ccm +++ b/nihil/command_map.ccm @@ -24,6 +24,13 @@ import :usage_error; namespace nihil { +export struct command; + +/* + * Register a command; used by command<>::command(). + */ +auto register_command(std::string_view path, command *) noexcept -> void; + /* * A command that can be invoked. Instantiating a command adds this command * to the global command table. If an error occurs, the program will abort. @@ -34,6 +41,7 @@ export struct command { , m_usage(usage) , m_handler(std::forward<decltype(fn)>(fn)) { + register_command(path, this); } [[nodiscard]] auto path(this command const &self) -> std::string_view @@ -52,11 +60,6 @@ private: std::function<int (int, char **)> m_handler; }; -/* - * Register a command; used by command<>::command(). - */ -auto register_command(std::string_view path, command *) noexcept -> void; - // The public API. export [[nodiscard]] auto dispatch_command(int argc, char **argv) -> int; export auto print_usage(std::string_view prefix) -> void; |
