]> rtime.felk.cvut.cz Git - notmuch.git/commitdiff
cli: add support for hierarchical command line option arrays
authorJani Nikula <jani@nikula.org>
Wed, 5 Nov 2014 00:25:54 +0000 (01:25 +0100)
committerDavid Bremner <david@tethera.net>
Wed, 5 Nov 2014 22:17:00 +0000 (23:17 +0100)
NOTMUCH_OPT_INHERIT expects a notmuch_opt_desc_t * pointer in
output_var.

The "Unrecognized option" message was moved out of parse_option() to
not be emitted twice or when parsing a non-inherited option.

command-line-arguments.c
command-line-arguments.h

index c6f7269603cbb3608186ee097a2ad993bbb5790e..de6b453684cbd1bff5177a974fc2ff7f4b92138f 100644 (file)
@@ -122,16 +122,18 @@ parse_position_arg (const char *arg_str, int pos_arg_index,
  */
 
 notmuch_bool_t
-parse_option (const char *arg,
-             const notmuch_opt_desc_t *options) {
-
-    assert(arg);
+parse_option (const char *_arg, const notmuch_opt_desc_t *options)
+{
+    assert(_arg);
     assert(options);
 
-    arg += 2;
-
+    const char *arg = _arg + 2; /* _arg starts with -- */
     const notmuch_opt_desc_t *try;
     for (try = options; try->opt_type != NOTMUCH_OPT_END; try++) {
+       if (try->opt_type == NOTMUCH_OPT_INHERIT &&
+           parse_option (_arg, try->output_var))
+           return TRUE;
+
        if (! try->name)
            continue;
 
@@ -170,7 +172,6 @@ parse_option (const char *arg,
            /*UNREACHED*/
        }
     }
-    fprintf (stderr, "Unrecognized option: --%s\n", arg);
     return FALSE;
 }
 
@@ -201,6 +202,7 @@ parse_arguments (int argc, char **argv,
            if (more_args) {
                opt_index++;
            } else {
+               fprintf (stderr, "Unrecognized option: %s\n", argv[opt_index]);
                opt_index = -1;
            }
 
index 6444129ad2d095e811fcb0d17b93d8fc42aa7166..309aaf2b37b89878ebeac38e0f67ebbfd7e4996b 100644 (file)
@@ -5,6 +5,7 @@
 
 enum notmuch_opt_type {
     NOTMUCH_OPT_END = 0,
+    NOTMUCH_OPT_INHERIT,       /* another options table */
     NOTMUCH_OPT_BOOLEAN,       /* --verbose              */
     NOTMUCH_OPT_INT,           /* --frob=8               */
     NOTMUCH_OPT_KEYWORD,       /* --format=raw|json|text */