aboutsummaryrefslogtreecommitdiff
path: root/src/stdlib/cli.h
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2025-08-31 12:58:59 -0400
committerBruce Hill <bruce@bruce-hill.com>2025-08-31 12:58:59 -0400
commit530b91d9e756830abffce9d96ed995e0fe3302b0 (patch)
treedc3df5990c6c45c4a2beea887269382bae7bd8b6 /src/stdlib/cli.h
parent07c5287760ca7a80c06dd80defe007ad009695fc (diff)
Move CLI parsing to its own file.
Diffstat (limited to 'src/stdlib/cli.h')
-rw-r--r--src/stdlib/cli.h21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/stdlib/cli.h b/src/stdlib/cli.h
new file mode 100644
index 00000000..a2058754
--- /dev/null
+++ b/src/stdlib/cli.h
@@ -0,0 +1,21 @@
+// Command line argument parsing
+
+#pragma once
+
+#include <stdbool.h>
+
+#include "datatypes.h"
+#include "types.h"
+
+typedef struct {
+ const char *name;
+ bool required;
+ const TypeInfo_t *type;
+ void *dest;
+} cli_arg_t;
+
+void _tomo_parse_args(int argc, char *argv[], Text_t usage, Text_t help, const char *version, int spec_len,
+ cli_arg_t spec[spec_len]);
+#define tomo_parse_args(argc, argv, usage, help, version, ...) \
+ _tomo_parse_args(argc, argv, usage, help, version, sizeof((cli_arg_t[]){__VA_ARGS__}) / sizeof(cli_arg_t), \
+ (cli_arg_t[]){__VA_ARGS__})