]> git.notmuchmail.org Git - notmuch/blob - test/arg-test.c
cli: use designated initializers for opt desc
[notmuch] / test / arg-test.c
1 #include <stdio.h>
2 #include "command-line-arguments.h"
3
4
5 int main(int argc, char **argv){
6
7     int opt_index=1;
8
9     int kw_val=0;
10     int fl_val=0;
11     int int_val=0;
12     const char *pos_arg1=NULL;
13     const char *pos_arg2=NULL;
14     const char *string_val=NULL;
15
16     notmuch_opt_desc_t options[] = {
17         { .opt_keyword = &kw_val, .name = "keyword", .keywords =
18           (notmuch_keyword_t []){ { "one", 1 },
19                                   { "two", 2 },
20                                   { 0, 0 } } },
21         { .opt_flags = &fl_val, .name = "flag", .keywords =
22           (notmuch_keyword_t []){ { "one",   1 << 0},
23                                   { "two",   1 << 1 },
24                                   { "three", 1 << 2 },
25                                   { 0, 0 } } },
26         { .opt_int = &int_val, .name = "int" },
27         { .opt_string = &string_val, .name = "string" },
28         { .opt_position = &pos_arg1 },
29         { .opt_position = &pos_arg2 },
30         { }
31     };
32
33     opt_index = parse_arguments(argc, argv, options, 1);
34
35     if (opt_index < 0)
36         return 1;
37
38     if (kw_val)
39         printf("keyword %d\n", kw_val);
40
41     if (fl_val)
42         printf("flags %d\n", fl_val);
43
44     if (int_val)
45         printf("int %d\n", int_val);
46
47     if (string_val)
48         printf("string %s\n", string_val);
49
50     if (pos_arg1)
51         printf("positional arg 1 %s\n", pos_arg1);
52
53     if (pos_arg2)
54         printf("positional arg 2 %s\n", pos_arg2);
55
56
57     for ( ; opt_index < argc ; opt_index ++) {
58         printf("non parsed arg %d = %s\n", opt_index, argv[opt_index]);
59     }
60
61     return 0;
62 }