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