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