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