Enhance argument parsing to allow spaces as separators (v2)

David Bremner david at tethera.net
Mon Jun 5 03:29:20 PDT 2017


This obsoletes

     id:20170509021719.13086-2-david at tethera.net

Compared to the previous version, this drops the use of enums for
exclude and entire-thread, adds a couple of tests, and some
documentation of option separators.

Interdiff follows

diff --git a/doc/man1/notmuch.rst b/doc/man1/notmuch.rst
index fbd7f381..5e238ae4 100644
--- a/doc/man1/notmuch.rst
+++ b/doc/man1/notmuch.rst
@@ -125,6 +125,20 @@ users to have their own notmuch related tools to be run via the
 notmuch command. By design, this does not allow notmuch's own commands
 to be overriden using external commands.
 
+OPTION SYNTAX
+-------------
+
+All options accepting an argument can be used with '=' or ':' as a
+separator. For the cases where it's not ambiguous (in particular
+excluding boolean options), a space can also be used. The following
+are all equivalent:
+
+::
+
+   notmuch --config=alt-config config get user.name
+   notmuch --config:alt-config config get user.name
+   notmuch --config alt-config config get user.name
+
 ENVIRONMENT
 ===========
 
diff --git a/notmuch-show.c b/notmuch-show.c
index f8d62a1a..472c8767 100644
--- a/notmuch-show.c
+++ b/notmuch-show.c
@@ -1009,18 +1009,6 @@ static const notmuch_show_format_t *formatters[] = {
     [NOTMUCH_FORMAT_RAW] = &format_raw,
 };
 
-enum {
-    ENTIRE_THREAD_DEFAULT = -1,
-    ENTIRE_THREAD_FALSE = FALSE,
-    ENTIRE_THREAD_TRUE = TRUE,
-};
-
-/* The following is to allow future options to be added more easily */
-enum {
-    EXCLUDE_FALSE = FALSE,
-    EXCLUDE_TRUE = TRUE,
-};
-
 int
 notmuch_show_command (notmuch_config_t *config, int argc, char *argv[])
 {
@@ -1036,8 +1024,11 @@ notmuch_show_command (notmuch_config_t *config, int argc, char *argv[])
 	.output_body = TRUE,
     };
     int format = NOTMUCH_FORMAT_NOT_SPECIFIED;
-    int exclude = EXCLUDE_TRUE;
-    int entire_thread = ENTIRE_THREAD_DEFAULT;
+    int exclude = TRUE;
+
+    /* This value corresponds to neither true nor false being passed
+     * on the command line */
+    int entire_thread = -1;
     notmuch_bool_t single_message;
 
     notmuch_opt_desc_t options[] = {
@@ -1095,7 +1086,7 @@ notmuch_show_command (notmuch_config_t *config, int argc, char *argv[])
 
     /* Default is entire-thread = FALSE except for format=json and
      * format=sexp. */
-    if (entire_thread == ENTIRE_THREAD_DEFAULT) {
+    if (entire_thread != FALSE && entire_thread != TRUE) {
 	if (format == NOTMUCH_FORMAT_JSON || format == NOTMUCH_FORMAT_SEXP)
 	    params.entire_thread = TRUE;
 	else
@@ -1175,7 +1166,7 @@ notmuch_show_command (notmuch_config_t *config, int argc, char *argv[])
 	    }
 	}
 
-	if (exclude == EXCLUDE_FALSE) {
+	if (exclude == FALSE) {
 	    notmuch_query_set_omit_excluded (query, FALSE);
 	    params.omit_excluded = FALSE;
 	}
diff --git a/test/T030-config.sh b/test/T030-config.sh
index 0915abdb..79a24948 100755
--- a/test/T030-config.sh
+++ b/test/T030-config.sh
@@ -69,6 +69,14 @@ notmuch --config=alt-config config set user.name "Another Name"
 test_expect_equal "$(notmuch --config=alt-config config get user.name)" \
     "Another Name"
 
+test_begin_subtest "Top level --config:FILE option"
+test_expect_equal "$(notmuch --config:alt-config config get user.name)" \
+    "Another Name"
+
+test_begin_subtest "Top level --config<space>FILE option"
+test_expect_equal "$(notmuch --config  alt-config config get user.name)" \
+    "Another Name"
+
 test_begin_subtest "Top level --config=FILE option changed the right file"
 test_expect_equal "$(notmuch config get user.name)" \
     "Notmuch Test Suite"


More information about the notmuch mailing list