Re: [PATCH v6 1/6] cli: command line parsing: allow default for keyword options
authorPeter Wang <novalazy@gmail.com>
Mon, 28 May 2012 13:31:52 +0000 (23:31 +1000)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:47:29 +0000 (09:47 -0800)
c9/d30a7e9cd671b05518c066bdb6e534bfbae9d1 [new file with mode: 0644]

diff --git a/c9/d30a7e9cd671b05518c066bdb6e534bfbae9d1 b/c9/d30a7e9cd671b05518c066bdb6e534bfbae9d1
new file mode 100644 (file)
index 0000000..c0d4890
--- /dev/null
@@ -0,0 +1,117 @@
+Return-Path: <novalazy@gmail.com>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+       by olra.theworths.org (Postfix) with ESMTP id A5B78431FAF\r
+       for <notmuch@notmuchmail.org>; Mon, 28 May 2012 06:32:00 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.799\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.799 tagged_above=-999 required=5\r
+       tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,\r
+       FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+       by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+       with ESMTP id WdEA05QfPXlf for <notmuch@notmuchmail.org>;\r
+       Mon, 28 May 2012 06:32:00 -0700 (PDT)\r
+Received: from mail-pz0-f53.google.com (mail-pz0-f53.google.com\r
+       [209.85.210.53]) (using TLSv1 with cipher RC4-MD5 (128/128 bits))\r
+       (No client certificate requested)\r
+       by olra.theworths.org (Postfix) with ESMTPS id 22794431FAE\r
+       for <notmuch@notmuchmail.org>; Mon, 28 May 2012 06:32:00 -0700 (PDT)\r
+Received: by dadg9 with SMTP id g9so5241732dad.26\r
+       for <notmuch@notmuchmail.org>; Mon, 28 May 2012 06:31:58 -0700 (PDT)\r
+DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113;\r
+       h=date:message-id:from:to:subject:in-reply-to:references:mime-version\r
+       :content-type:content-disposition:content-transfer-encoding;\r
+       bh=UgTQwJanb1bgx2Hjg0aaMK0wv7oJj6K8eWJv308CGsg=;\r
+       b=NrJIUws8kYTEDYEP4YLy+5bK8G8eYbII5VgDQko+Y1J+RcMGC0FACyoV91B9G/sZ/Y\r
+       681Ht5tq34eFkaTIARvMtmLxGysfmh0ansFibsDaAH8slT+C12sTiRWX3OEviIq7CkDY\r
+       zAQBdt/vufCgJkh2HbOtFwqeu4qwbsOrS8suImVHSx1ecuKZVTUMDhC/9PgPJwi52cmW\r
+       KvVToiMI2FaatFlhCVv+wTy4j+RgNwSu/uvJpppM+pqqtjiA0vQ+IynQU8XU3eluCqiF\r
+       q+gBOUX3QhcGTO/hwjWIAIGgLanIhYlp0dqYuQSuKUCvyYbFdtlQrC43a9bAu5qM32dI\r
+       hwDQ==\r
+Received: by 10.68.233.102 with SMTP id tv6mr27313781pbc.153.1338211918235;\r
+       Mon, 28 May 2012 06:31:58 -0700 (PDT)\r
+Received: from localhost (215.42.233.220.static.exetel.com.au.\r
+       [220.233.42.215])\r
+       by mx.google.com with ESMTPS id rv5sm19298330pbc.56.2012.05.28.06.31.55\r
+       (version=TLSv1/SSLv3 cipher=OTHER);\r
+       Mon, 28 May 2012 06:31:56 -0700 (PDT)\r
+Date: Mon, 28 May 2012 23:31:52 +1000\r
+Message-ID: <20120528233152.GD2331@hili.localdomain>\r
+From: Peter Wang <novalazy@gmail.com>\r
+To: notmuch@notmuchmail.org\r
+Subject: Re: [PATCH v6 1/6] cli: command line parsing: allow default for\r
+       keyword options\r
+In-Reply-To: <1338106946-7611-2-git-send-email-markwalters1009@gmail.com>\r
+References: <1338106946-7611-1-git-send-email-markwalters1009@gmail.com>\r
+       <1338106946-7611-2-git-send-email-markwalters1009@gmail.com>\r
+MIME-Version: 1.0\r
+Content-Type: text/plain; charset=utf-8\r
+Content-Disposition: inline\r
+Content-Transfer-Encoding: 8bit\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+       <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Mon, 28 May 2012 13:32:00 -0000\r
+\r
+On Sun, 27 May 2012 09:22:21 +0100, Mark Walters <markwalters1009@gmail.com> wrote:\r
+> This changes the parsing for "keyword" options so that if the option\r
+> is specified with no argument the argument is parsed as if it were\r
+> passed an empty string. This make it easier to add options to existing\r
+> boolean arguments (the existing --option can default to TRUE).\r
+> ---\r
+>  command-line-arguments.c |   17 +++++++++++++----\r
+>  1 files changed, 13 insertions(+), 4 deletions(-)\r
+> \r
+> diff --git a/command-line-arguments.c b/command-line-arguments.c\r
+> index 76b185f..2fb8a1b 100644\r
+> --- a/command-line-arguments.c\r
+> +++ b/command-line-arguments.c\r
+> @@ -11,10 +11,15 @@\r
+>  */\r
+>  \r
+>  static notmuch_bool_t\r
+> -_process_keyword_arg (const notmuch_opt_desc_t *arg_desc, const char *arg_str) {\r
+> +_process_keyword_arg (const notmuch_opt_desc_t *arg_desc, char next, const char *arg_str) {\r
+>  \r
+>      const notmuch_keyword_t *keywords = arg_desc->keywords;\r
+>  \r
+> +    if (next == 0) {\r
+> +    /* No keyword given */\r
+> +    arg_str="";\r
+> +    }\r
+> +\r
+\r
+Whitespace.\r
+\r
+>      while (keywords->name) {\r
+>      if (strcmp (arg_str, keywords->name) == 0) {\r
+>          if (arg_desc->output_var) {\r
+> @@ -24,7 +29,10 @@ _process_keyword_arg (const notmuch_opt_desc_t *arg_desc, const char *arg_str) {\r
+>      }\r
+>      keywords++;\r
+>      }\r
+> -    fprintf (stderr, "unknown keyword: %s\n", arg_str);\r
+> +    if (next!=0)\r
+\r
+Whitespace.\r
+\r
+> +    fprintf (stderr, "unknown keyword: %s\n", arg_str);\r
+> +    else\r
+> +    fprintf (stderr, "option %s needs a keyword\n", arg_desc->name);\r
+\r
+I think "keyword argument" is clearer.\r
+\r
+Peter\r