From 35ff96b08ef09dc91005472b5ea88b4acdf40041 Mon Sep 17 00:00:00 2001 From: Lexi Winter Date: Fri, 27 Jun 2025 13:23:47 +0100 Subject: nihil: fix command_map registration --- nihil/command_map.cc | 2 +- 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 { 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(fn)) { + register_command(path, this); } [[nodiscard]] auto path(this command const &self) -> std::string_view @@ -52,11 +60,6 @@ private: std::function 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; -- cgit v1.2.3