aboutsummaryrefslogtreecommitdiff
path: root/src/stdlib/cli.h
blob: a2058754641dacd7553df002ebb5faf75429c841 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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__})