From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by arlo.cworth.org (Postfix) with ESMTP id 336F36DE01C2 for ; Mon, 5 Jun 2017 03:29:48 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at cworth.org X-Spam-Flag: NO X-Spam-Score: -0.001 X-Spam-Level: X-Spam-Status: No, score=-0.001 tagged_above=-999 required=5 tests=[AWL=0.010, SPF_PASS=-0.001, T_RP_MATCHES_RCVD=-0.01] autolearn=disabled Received: from arlo.cworth.org ([127.0.0.1]) by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id RJZ93Rj7ZPxE for ; Mon, 5 Jun 2017 03:29:45 -0700 (PDT) Received: from fethera.tethera.net (fethera.tethera.net [198.245.60.197]) by arlo.cworth.org (Postfix) with ESMTPS id 208586DE0352 for ; Mon, 5 Jun 2017 03:29:44 -0700 (PDT) Received: from remotemail by fethera.tethera.net with local (Exim 4.84_2) (envelope-from ) id 1dHpFb-0006R0-OD; Mon, 05 Jun 2017 06:28:43 -0400 Received: (nullmailer pid 1339 invoked by uid 1000); Mon, 05 Jun 2017 10:29:39 -0000 From: David Bremner To: notmuch@notmuchmail.org, notmuch@freelists.org Subject: [patch v2 3/3] cli: add space separator for keyword, string, and int arguments Date: Mon, 5 Jun 2017 07:29:23 -0300 Message-Id: <20170605102923.1268-4-david@tethera.net> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170605102923.1268-1-david@tethera.net> References: <20170605102923.1268-1-david@tethera.net> X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 05 Jun 2017 10:29:48 -0000 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 | 46 +++++++++++++++++++++++++++++++++++++++++- 4 files changed, 78 insertions(+), 1 deletion(-) diff --git a/command-line-arguments.c b/command-line-arguments.c index 72b950e9..91e9e06f 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 --configFILE 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 01592749..01de88eb 100755 --- a/test/T690-command-line-args.sh +++ b/test/T690-command-line-args.sh @@ -3,9 +3,53 @@ test_description="command line arguments" . ./test-lib.sh || exit 1 -NOTMUCH_NEW > /dev/null +add_message test_begin_subtest 'bad option to show' test_expect_code 1 'notmuch show --this-is-not-an-option' +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 'single keyword option with space' +cat < 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 < 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 < EXPECTED +["msg-001@notmuch-test-suite"] +EOF +notmuch search --output messages --format=json '*' >& OUTPUT +test_expect_equal_file EXPECTED OUTPUT + +test_begin_subtest 'keyword option with =' +cat < 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