X-Git-Url: https://git.notmuchmail.org/git?a=blobdiff_plain;f=test%2Farg-test.c;h=9d13618bd17c004e8dfbc822b08a5ef587a0d56d;hb=e8cba9da18a8ed946738fdd9f47d117c1110c1b4;hp=adc56e30e7d97e449a328ed8ff7642b429084b7b;hpb=5800a44bd5b77390d2243426f0c82de4d0495a1c;p=notmuch diff --git a/test/arg-test.c b/test/arg-test.c index adc56e30..9d13618b 100644 --- a/test/arg-test.c +++ b/test/arg-test.c @@ -7,30 +7,45 @@ int main(int argc, char **argv){ int opt_index=1; int kw_val=0; + int fl_val=0; int int_val=0; - char *pos_arg1=NULL; - char *pos_arg2=NULL; - char *string_val=NULL; + const char *pos_arg1=NULL; + const char *pos_arg2=NULL; + const char *string_val=NULL; + notmuch_bool_t bool_val = FALSE; notmuch_opt_desc_t options[] = { - { NOTMUCH_OPT_KEYWORD, &kw_val, "keyword", 'k', + { .opt_bool = &bool_val, .name = "boolean" }, + { .opt_keyword = &kw_val, .name = "keyword", .keywords = (notmuch_keyword_t []){ { "one", 1 }, { "two", 2 }, { 0, 0 } } }, - { NOTMUCH_OPT_INT, &int_val, "int", 'i', 0}, - { NOTMUCH_OPT_STRING, &string_val, "string", 's', 0}, - { NOTMUCH_OPT_POSITION, &pos_arg1, 0,0, 0}, - { NOTMUCH_OPT_POSITION, &pos_arg2, 0,0, 0}, - { 0, 0, 0, 0, 0 } }; + { .opt_flags = &fl_val, .name = "flag", .keywords = + (notmuch_keyword_t []){ { "one", 1 << 0}, + { "two", 1 << 1 }, + { "three", 1 << 2 }, + { 0, 0 } } }, + { .opt_int = &int_val, .name = "int" }, + { .opt_string = &string_val, .name = "string" }, + { .opt_position = &pos_arg1 }, + { .opt_position = &pos_arg2 }, + { } + }; opt_index = parse_arguments(argc, argv, options, 1); if (opt_index < 0) return 1; + if (bool_val) + printf("boolean %d\n", bool_val); + if (kw_val) printf("keyword %d\n", kw_val); + if (fl_val) + printf("flags %d\n", fl_val); + if (int_val) printf("int %d\n", int_val); @@ -41,7 +56,7 @@ int main(int argc, char **argv){ printf("positional arg 1 %s\n", pos_arg1); if (pos_arg2) - printf("positional arg 2 %s\n", pos_arg1); + printf("positional arg 2 %s\n", pos_arg2); for ( ; opt_index < argc ; opt_index ++) {