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