[RFC PATCH 1/2] cli: add support for hierarchical command line option arrays

Jani Nikula jani at nikula.org
Sat Nov 1 04:30:47 PDT 2014


NOTMUCH_OPT_INHERIT expects a notmuch_opt_desc_t * pointer in
output_var.
---
 command-line-arguments.c | 11 +++++++----
 command-line-arguments.h |  1 +
 2 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/command-line-arguments.c b/command-line-arguments.c
index c6f7269603cb..eb977d0a6fa9 100644
--- a/command-line-arguments.c
+++ b/command-line-arguments.c
@@ -122,16 +122,19 @@ 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) {
+parse_option (const char *_arg, const notmuch_opt_desc_t *options)
+{
+    const char *arg = _arg + 2; /* _arg starts with -- */
 
     assert(arg);
     assert(options);
 
-    arg += 2;
-
     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;
 
diff --git a/command-line-arguments.h b/command-line-arguments.h
index 6444129ad2d0..309aaf2b37b8 100644
--- a/command-line-arguments.h
+++ b/command-line-arguments.h
@@ -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 */
-- 
2.1.1



More information about the notmuch mailing list