unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: David Bremner <david@tethera.net>
To: notmuch@freelists.org, notmuch@notmuchmail.org
Subject: [PATCH 3/3] cli: add space separator for keyword, string, and int arguments
Date: Sat,  1 Jul 2017 12:18:45 -0300	[thread overview]
Message-ID: <20170701151845.10942-4-david@tethera.net> (raw)
In-Reply-To: <20170701151845.10942-1-david@tethera.net>

Defer the complication of optional boolean arguments for later (never?).
---
 command-line-arguments.c       | 11 +++++++
 doc/man1/notmuch.rst           | 14 ++++++++
 test/T030-config.sh            |  8 +++++
 test/T690-command-line-args.sh | 72 +++++++++++++++++++++++++++++++++++++++++-
 4 files changed, 104 insertions(+), 1 deletion(-)

diff --git a/command-line-arguments.c b/command-line-arguments.c
index a489612f..dc517b06 100644
--- a/command-line-arguments.c
+++ b/command-line-arguments.c
@@ -133,6 +133,11 @@ parse_option (int argc, char **argv, const notmuch_opt_desc_t *options, int opt_
 
     const char *arg = _arg + 2; /* _arg starts with -- */
     const notmuch_opt_desc_t *try;
+
+    const char *next_arg = NULL;
+    if (opt_index < argc - 1  && strncmp (argv[opt_index + 1], "--", 2) != 0)
+	next_arg = argv[opt_index + 1];
+
     for (try = options; try->opt_type != NOTMUCH_OPT_END; try++) {
 	if (try->opt_type == NOTMUCH_OPT_INHERIT) {
 	    int new_index = parse_option (argc, argv, try->output_var, opt_index);
@@ -158,6 +163,12 @@ parse_option (int argc, char **argv, const notmuch_opt_desc_t *options, int opt_
 	if (next != '=' && next != ':' && next != '\0')
 	    continue;
 
+	if (next == '\0' && next_arg != NULL && try->opt_type != NOTMUCH_OPT_BOOLEAN) {
+	    next = ' ';
+	    value = next_arg;
+	    opt_index ++;
+	}
+
 	if (try->output_var == NULL)
 	    INTERNAL_ERROR ("output pointer NULL for option %s", try->name);
 
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/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"
diff --git a/test/T690-command-line-args.sh b/test/T690-command-line-args.sh
index 8711bec2..a4f4b5f5 100755
--- a/test/T690-command-line-args.sh
+++ b/test/T690-command-line-args.sh
@@ -3,7 +3,7 @@
 test_description="command line arguments"
 . ./test-lib.sh || exit 1
 
-NOTMUCH_NEW > /dev/null
+add_message
 
 test_begin_subtest 'bad option to show'
 notmuch show --frobnicate >& OUTPUT
@@ -12,4 +12,74 @@ Unrecognized option: --frobnicate
 EOF
 test_expect_equal_file EXPECTED OUTPUT
 
+test_begin_subtest 'string option with space'
+cp /dev/null EXPECTED
+notmuch dump --output foo.txt '*' >& OUTPUT
+test_expect_equal_file EXPECTED OUTPUT
+
+test_begin_subtest 'string option with ='
+cp /dev/null EXPECTED
+notmuch dump --output=foo.txt '*' >& OUTPUT
+test_expect_equal_file EXPECTED OUTPUT
+
+test_begin_subtest 'string option with :'
+cp /dev/null EXPECTED
+notmuch dump --output:foo.txt '*' >& OUTPUT
+test_expect_equal_file EXPECTED OUTPUT
+
+test_begin_subtest 'single keyword option with space'
+cat <<EOF > EXPECTED
+id:msg-001@notmuch-test-suite
+EOF
+notmuch search --output messages '*' >& OUTPUT
+test_expect_equal_file EXPECTED OUTPUT
+
+test_begin_subtest 'single keyword option with ='
+cat <<EOF > EXPECTED
+id:msg-001@notmuch-test-suite
+EOF
+notmuch search --output=messages '*' >& OUTPUT
+test_expect_equal_file EXPECTED OUTPUT
+
+test_begin_subtest 'single keyword option with :'
+cat <<EOF > EXPECTED
+id:msg-001@notmuch-test-suite
+EOF
+notmuch search --output:messages '*' >& OUTPUT
+test_expect_equal_file EXPECTED OUTPUT
+
+test_begin_subtest 'multiple keyword options with space'
+cat <<EOF > EXPECTED
+["msg-001@notmuch-test-suite"]
+EOF
+notmuch search --output messages --format json '*' >& OUTPUT
+test_expect_equal_file EXPECTED OUTPUT
+
+test_begin_subtest 'multiple keyword options with ='
+cat <<EOF > EXPECTED
+["msg-001@notmuch-test-suite"]
+EOF
+notmuch search --output=messages --format=json '*' >& OUTPUT
+test_expect_equal_file EXPECTED OUTPUT
+
+test_begin_subtest 'mixed space and = delimiters'
+cat <<EOF > EXPECTED
+["msg-001@notmuch-test-suite"]
+EOF
+notmuch search --output messages --format=json '*' >& OUTPUT
+test_expect_equal_file EXPECTED OUTPUT
+
+test_begin_subtest 'mixed space and : delimiters'
+cat <<EOF > EXPECTED
+["msg-001@notmuch-test-suite"]
+EOF
+notmuch search --output:messages --format json '*' >& OUTPUT
+test_expect_equal_file EXPECTED OUTPUT
+
+test_begin_subtest 'show --entire-thread'
+test_expect_success 'notmuch show --entire-thread tag:test > /dev/null'
+
+test_begin_subtest 'show --exclude'
+test_expect_success 'notmuch show --exclude tag:test > /dev/null'
+
 test_done
-- 
2.11.0

  parent reply	other threads:[~2017-07-01 15:19 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-07-01 15:18 v3 of spaces command line argument separator David Bremner
2017-07-01 15:18 ` [PATCH 1/3] cli/show: convert keyword options to booleans David Bremner
2017-07-01 15:18 ` [PATCH 2/3] cli: change api of parse_option David Bremner
2017-07-01 15:18 ` David Bremner [this message]
2017-07-12 20:50 ` v3 of spaces command line argument separator David Bremner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://notmuchmail.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170701151845.10942-4-david@tethera.net \
    --to=david@tethera.net \
    --cc=notmuch@freelists.org \
    --cc=notmuch@notmuchmail.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).