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 751456DE2788 for ; Sat, 1 Jul 2017 08:19:04 -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 kONlRrl185da for ; Sat, 1 Jul 2017 08:19:03 -0700 (PDT) Received: from fethera.tethera.net (fethera.tethera.net [198.245.60.197]) by arlo.cworth.org (Postfix) with ESMTPS id 66DC46DE2786 for ; Sat, 1 Jul 2017 08:19:03 -0700 (PDT) Received: from remotemail by fethera.tethera.net with local (Exim 4.84_2) (envelope-from ) id 1dRK7g-0002In-0s; Sat, 01 Jul 2017 11:15:48 -0400 Received: (nullmailer pid 11071 invoked by uid 1000); Sat, 01 Jul 2017 15:18:59 -0000 From: David Bremner To: notmuch@freelists.org, notmuch@notmuchmail.org Subject: v3 of spaces command line argument separator Date: Sat, 1 Jul 2017 12:18:42 -0300 Message-Id: <20170701151845.10942-1-david@tethera.net> X-Mailer: git-send-email 2.11.0 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: Sat, 01 Jul 2017 15:19:04 -0000 This obsoletes: id:20170605102923.1268-1-david@tethera.net Compared to the previous version this - rewrites the switch in parse_option in a less fancy way - fixes the error message for unrecognize options - adds some tests for --arg:val diff --git a/command-line-arguments.c b/command-line-arguments.c index 91e9e06f..dc517b06 100644 --- a/command-line-arguments.c +++ b/command-line-arguments.c @@ -172,22 +172,31 @@ parse_option (int argc, char **argv, const notmuch_opt_desc_t *options, int opt_ if (try->output_var == NULL) INTERNAL_ERROR ("output pointer NULL for option %s", try->name); + notmuch_bool_t opt_status = FALSE; switch (try->opt_type) { case NOTMUCH_OPT_KEYWORD: case NOTMUCH_OPT_KEYWORD_FLAGS: - return _process_keyword_arg (try, next, value) ? opt_index + 1 : (-1); + opt_status = _process_keyword_arg (try, next, value); + break; case NOTMUCH_OPT_BOOLEAN: - return _process_boolean_arg (try, next, value) ? opt_index + 1 : (-1); + opt_status = _process_boolean_arg (try, next, value); + break; case NOTMUCH_OPT_INT: - return _process_int_arg (try, next, value) ? opt_index + 1 : (-1); + opt_status = _process_int_arg (try, next, value); + break; case NOTMUCH_OPT_STRING: - return _process_string_arg (try, next, value) ? opt_index + 1 : (-1); + opt_status = _process_string_arg (try, next, value); + break; case NOTMUCH_OPT_POSITION: case NOTMUCH_OPT_END: default: INTERNAL_ERROR ("unknown or unhandled option type %d", try->opt_type); /*UNREACHED*/ } + if (opt_status) + return opt_index+1; + else + return -1; } return -1; } @@ -211,13 +220,14 @@ parse_arguments (int argc, char **argv, } } else { + int prev_opt_index = opt_index; + if (strlen (argv[opt_index]) == 2) return opt_index+1; opt_index = parse_option (argc, argv, options, opt_index); - /* this is currently broken as -1 is never returned */ if (opt_index < 0) { - fprintf (stderr, "Unrecognized option: %s\n", argv[opt_index]); + fprintf (stderr, "Unrecognized option: %s\n", argv[prev_opt_index]); more_args = FALSE; } } diff --git a/test/T690-command-line-args.sh b/test/T690-command-line-args.sh index 01de88eb..a4f4b5f5 100755 --- a/test/T690-command-line-args.sh +++ b/test/T690-command-line-args.sh @@ -6,7 +6,11 @@ test_description="command line arguments" add_message test_begin_subtest 'bad option to show' -test_expect_code 1 'notmuch show --this-is-not-an-option' +notmuch show --frobnicate >& OUTPUT +cat < EXPECTED +Unrecognized option: --frobnicate +EOF +test_expect_equal_file EXPECTED OUTPUT test_begin_subtest 'string option with space' cp /dev/null EXPECTED @@ -18,6 +22,11 @@ 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 @@ -25,6 +34,20 @@ EOF notmuch search --output messages '*' >& OUTPUT test_expect_equal_file EXPECTED OUTPUT +test_begin_subtest 'single keyword option with =' +cat < 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 < 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"] @@ -32,6 +55,13 @@ EOF notmuch search --output messages --format json '*' >& OUTPUT test_expect_equal_file EXPECTED OUTPUT +test_begin_subtest 'multiple keyword options 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 'mixed space and = delimiters' cat < EXPECTED ["msg-001@notmuch-test-suite"] @@ -39,11 +69,11 @@ EOF notmuch search --output messages --format=json '*' >& OUTPUT test_expect_equal_file EXPECTED OUTPUT -test_begin_subtest 'keyword option with =' +test_begin_subtest 'mixed space and : delimiters' cat < EXPECTED ["msg-001@notmuch-test-suite"] EOF -notmuch search --output=messages --format=json '*' >& OUTPUT +notmuch search --output:messages --format json '*' >& OUTPUT test_expect_equal_file EXPECTED OUTPUT test_begin_subtest 'show --entire-thread'