diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2025-08-31 12:58:59 -0400 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2025-08-31 12:58:59 -0400 |
| commit | 530b91d9e756830abffce9d96ed995e0fe3302b0 (patch) | |
| tree | dc3df5990c6c45c4a2beea887269382bae7bd8b6 /src/stdlib/cli.h | |
| parent | 07c5287760ca7a80c06dd80defe007ad009695fc (diff) | |
Move CLI parsing to its own file.
Diffstat (limited to 'src/stdlib/cli.h')
| -rw-r--r-- | src/stdlib/cli.h | 21 |
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__}) |
