aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--nihil/command_map.cc2
-rw-r--r--nihil/command_map.ccm13
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;