aboutsummaryrefslogtreecommitdiffstats
path: root/nihil.cli/dispatch_command.ccm
diff options
context:
space:
mode:
authorLexi Winter <lexi@le-fay.org>2025-06-29 00:42:31 +0100
committerLexi Winter <lexi@le-fay.org>2025-06-29 00:42:31 +0100
commitd24315268c11d435bb9accbce87b7f46dda6ed3e (patch)
tree66589cb6a15fa74d4b09683105c583e4a5c222b4 /nihil.cli/dispatch_command.ccm
parent7741a9698d29f79aca3e47495dcdf87c7a712f42 (diff)
downloadnihil-d24315268c11d435bb9accbce87b7f46dda6ed3e.tar.gz
nihil-d24315268c11d435bb9accbce87b7f46dda6ed3e.tar.bz2
cli: improve command dispatch a bit
Diffstat (limited to 'nihil.cli/dispatch_command.ccm')
-rw-r--r--nihil.cli/dispatch_command.ccm31
1 files changed, 31 insertions, 0 deletions
diff --git a/nihil.cli/dispatch_command.ccm b/nihil.cli/dispatch_command.ccm
new file mode 100644
index 0000000..1ba55bb
--- /dev/null
+++ b/nihil.cli/dispatch_command.ccm
@@ -0,0 +1,31 @@
+/*
+ * This source code is released into the public domain.
+ */
+
+module;
+
+#include <functional>
+#include <iostream>
+#include <map>
+#include <string>
+#include <utility>
+
+export module nihil.cli:dispatch_command;
+
+import nihil.util;
+import :command;
+import :usage_error;
+
+namespace nihil {
+
+/*
+ * Invoke a command (which must have been previously registered) using
+ * the provided argument vector.
+ *
+ * The caller should have already stripped the executable name from argv[0]
+ * so that the vector starts with the command name. This is implicitly
+ * done if main() uses getopt().
+ */
+export [[nodiscard]] auto dispatch_command(int argc, char **argv) -> int;
+
+} // namespace nihil