]> git.notmuchmail.org Git - notmuch/blob - test/arg-test.c
tests/smime: fix typo in README
[notmuch] / test / arg-test.c
1 #include <stdio.h>
2 #include "command-line-arguments.h"
3
4
5 int
6 main (int argc, char **argv)
7 {
8
9     int opt_index = 1;
10
11     int kw_val = 0;
12     int kwb_val = 0;
13     int fl_val = 0;
14     int int_val = 0;
15     const char *pos_arg1 = NULL;
16     const char *pos_arg2 = NULL;
17     const char *string_val = NULL;
18     bool bool_val = false;
19     bool fl_set = false, int_set = false, bool_set = false, kwb_set = false,
20          kw_set = false, string_set = false, pos1_set = false, pos2_set = false;
21
22     notmuch_opt_desc_t parent_options[] = {
23         { .opt_flags = &fl_val, .name = "flag", .present = &fl_set, .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", .present = &int_set },
29         { }
30     };
31
32     notmuch_opt_desc_t options[] = {
33         { .opt_bool = &bool_val, .name = "boolean", .present = &bool_set },
34         { .opt_keyword = &kw_val, .name = "keyword", .present = &kw_set, .keywords =
35               (notmuch_keyword_t []){ { "zero", 0 },
36                                       { "one", 1 },
37                                       { "two", 2 },
38                                       { 0, 0 } } },
39         { .opt_keyword = &kwb_val, .name = "boolkeyword", .present = &kwb_set,
40           .keyword_no_arg_value = "true", .keywords =
41               (notmuch_keyword_t []){ { "false", 0 },
42                                       { "true", 1 },
43                                       { "auto", 2 },
44                                       { 0, 0 } } },
45         { .opt_inherit = parent_options },
46         { .opt_string = &string_val, .name = "string", .present = &string_set },
47         { .opt_position = &pos_arg1, .present = &pos1_set },
48         { .opt_position = &pos_arg2, .present = &pos2_set },
49         { }
50     };
51
52     opt_index = parse_arguments (argc, argv, options, 1);
53
54     if (opt_index < 0)
55         return 1;
56
57     if (bool_set)
58         printf ("boolean %d\n", bool_val);
59
60     if (kw_set)
61         printf ("keyword %d\n", kw_val);
62
63     if (kwb_set)
64         printf ("boolkeyword %d\n", kwb_val);
65
66     if (fl_set)
67         printf ("flags %d\n", fl_val);
68
69     if (int_set)
70         printf ("int %d\n", int_val);
71
72     if (string_set)
73         printf ("string %s\n", string_val);
74
75     if (pos1_set)
76         printf ("positional arg 1 %s\n", pos_arg1);
77
78     if (pos2_set)
79         printf ("positional arg 2 %s\n", pos_arg2);
80
81
82     for (; opt_index < argc; opt_index++) {
83         printf ("non parsed arg %d = %s\n", opt_index, argv[opt_index]);
84     }
85
86     return 0;
87 }