]> git.notmuchmail.org Git - notmuch/blob - command-line-arguments.h
cli: update to use new count API
[notmuch] / command-line-arguments.h
1 #ifndef NOTMUCH_OPTS_H
2 #define NOTMUCH_OPTS_H
3
4 #include "notmuch.h"
5
6 enum notmuch_opt_type {
7     NOTMUCH_OPT_END = 0,
8     NOTMUCH_OPT_INHERIT,        /* another options table */
9     NOTMUCH_OPT_BOOLEAN,        /* --verbose              */
10     NOTMUCH_OPT_INT,            /* --frob=8               */
11     NOTMUCH_OPT_KEYWORD,        /* --format=raw|json|text */
12     NOTMUCH_OPT_KEYWORD_FLAGS,  /* the above with values OR'd together */
13     NOTMUCH_OPT_STRING,         /* --file=/tmp/gnarf.txt  */
14     NOTMUCH_OPT_POSITION        /* notmuch dump pos_arg   */
15 };
16
17 /*
18  * Describe one of the possibilities for a keyword option
19  * 'value' will be copied to the output variable
20  */
21
22 typedef struct notmuch_keyword {
23     const char *name;
24     int value;
25 } notmuch_keyword_t;
26
27 /*
28  * Describe one option.
29  *
30  * First two parameters are mandatory.
31  *
32  * name is mandatory _except_ for positional arguments.
33  *
34  * arg_id is currently unused, but could define short arguments.
35  *
36  * keywords is a (possibly NULL) pointer to an array of keywords
37  */
38 typedef struct notmuch_opt_desc {
39     enum notmuch_opt_type opt_type;
40     void *output_var;
41     const char *name;
42     int  arg_id;
43     const struct notmuch_keyword *keywords;
44 } notmuch_opt_desc_t;
45
46
47 /*
48   This is the main entry point for command line argument parsing.
49
50   Parse command line arguments according to structure options,
51   starting at position opt_index.
52
53   All output of parsed values is via pointers in options.
54
55   Parsing stops at -- (consumed) or at the (k+1)st argument
56   not starting with -- (a "positional argument") if options contains
57   k positional argument descriptors.
58
59   Returns the index of first non-parsed argument, or -1 in case of error.
60
61 */
62 int
63 parse_arguments (int argc, char **argv, const notmuch_opt_desc_t *options, int opt_index);
64
65 /*
66  * If the argument parsing loop provided by parse_arguments is not
67  * flexible enough, then the user might be interested in the following
68  * routines, but note that the API to parse_option might have to
69  * change. See command-line-arguments.c for descriptions of these
70  * functions.
71  */
72
73 notmuch_bool_t
74 parse_option (const char *arg, const notmuch_opt_desc_t* options);
75
76 notmuch_bool_t
77 parse_position_arg (const char *arg,
78                     int position_arg_index,
79                     const notmuch_opt_desc_t* options);
80
81
82 #endif