]> git.notmuchmail.org Git - notmuch/blob - test/arg-test.c
test: add opt_inherit to arg-test
[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     notmuch_bool_t bool_val = FALSE;
16
17     notmuch_opt_desc_t parent_options[] = {
18         { .opt_flags = &fl_val, .name = "flag", .keywords =
19           (notmuch_keyword_t []){ { "one",   1 << 0},
20                                   { "two",   1 << 1 },
21                                   { "three", 1 << 2 },
22                                   { 0, 0 } } },
23         { .opt_int = &int_val, .name = "int" },
24         { }
25     };
26
27     notmuch_opt_desc_t options[] = {
28         { .opt_bool = &bool_val, .name = "boolean" },
29         { .opt_keyword = &kw_val, .name = "keyword", .keywords =
30           (notmuch_keyword_t []){ { "one", 1 },
31                                   { "two", 2 },
32                                   { 0, 0 } } },
33         { .opt_inherit = parent_options },
34         { .opt_string = &string_val, .name = "string" },
35         { .opt_position = &pos_arg1 },
36         { .opt_position = &pos_arg2 },
37         { }
38     };
39
40     opt_index = parse_arguments(argc, argv, options, 1);
41
42     if (opt_index < 0)
43         return 1;
44
45     if (bool_val)
46         printf("boolean %d\n", bool_val);
47
48     if (kw_val)
49         printf("keyword %d\n", kw_val);
50
51     if (fl_val)
52         printf("flags %d\n", fl_val);
53
54     if (int_val)
55         printf("int %d\n", int_val);
56
57     if (string_val)
58         printf("string %s\n", string_val);
59
60     if (pos_arg1)
61         printf("positional arg 1 %s\n", pos_arg1);
62
63     if (pos_arg2)
64         printf("positional arg 2 %s\n", pos_arg2);
65
66
67     for ( ; opt_index < argc ; opt_index ++) {
68         printf("non parsed arg %d = %s\n", opt_index, argv[opt_index]);
69     }
70
71     return 0;
72 }