Re: [PATCH v5 1/5] cli: command line parsing: allow default for keyword options
authorPeter Wang <novalazy@gmail.com>
Sun, 27 May 2012 02:32:53 +0000 (12:32 +1000)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:47:27 +0000 (09:47 -0800)
90/522442ed998171bec4d1c0b4549430a86b771d [new file with mode: 0644]

diff --git a/90/522442ed998171bec4d1c0b4549430a86b771d b/90/522442ed998171bec4d1c0b4549430a86b771d
new file mode 100644 (file)
index 0000000..c93d2f1
--- /dev/null
@@ -0,0 +1,102 @@
+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 96B1E431FB6\r
+       for <notmuch@notmuchmail.org>; Sat, 26 May 2012 19:33:02 -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 KvxIS+UkP-g6 for <notmuch@notmuchmail.org>;\r
+       Sat, 26 May 2012 19:33:00 -0700 (PDT)\r
+Received: from mail-pb0-f53.google.com (mail-pb0-f53.google.com\r
+       [209.85.160.53]) (using TLSv1 with cipher RC4-MD5 (128/128 bits))\r
+       (No client certificate requested)\r
+       by olra.theworths.org (Postfix) with ESMTPS id 669E3431FAF\r
+       for <notmuch@notmuchmail.org>; Sat, 26 May 2012 19:33:00 -0700 (PDT)\r
+Received: by pbbrr13 with SMTP id rr13so4009919pbb.26\r
+       for <notmuch@notmuchmail.org>; Sat, 26 May 2012 19:32:59 -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=Q5Md19suo1Z8i6GVONL+GJqDpUlMAXw/Dt7aKmwj1lQ=;\r
+       b=FOox/St+AugHXGKEid+/yv5QKsIrMnZ/lzbz06Vxz2oEW+QbZ21gPnhNJNOcTGQkMr\r
+       O/JI7DlD2bYhHeyLGtHkjdSCZjjKdgzwp4CmG4fKw1ObweoPOK2u7LwOQEKWi4g9KlR9\r
+       InxCvAT+9ZCRbFJw0VZXVyIYxeONpkZPGUUE1Z+AsmOYMZoJ43eugXqRiidJSvl0aSB8\r
+       n0x9IrsD9sY9fLmyOlrBG3h/afrkm1eOOBrKhRItRi7n6ef1B8SqzmWIw+xYl/I4znYK\r
+       dx9IaOEeNA69BBoxc0Fqy4PhVnbjsBRNmcQPhRc4dcxGbYEFaKthHly5lygmNgzt7QAP\r
+       dEtA==\r
+Received: by 10.68.226.73 with SMTP id rq9mr12743599pbc.145.1338085979578;\r
+       Sat, 26 May 2012 19:32:59 -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 rj4sm14338466pbc.30.2012.05.26.19.32.56\r
+       (version=TLSv1/SSLv3 cipher=OTHER);\r
+       Sat, 26 May 2012 19:32:57 -0700 (PDT)\r
+Date: Sun, 27 May 2012 12:32:53 +1000\r
+Message-ID: <20120527123253.GA3049@hili.localdomain>\r
+From: Peter Wang <novalazy@gmail.com>\r
+To: notmuch@notmuchmail.org\r
+Subject: Re: [PATCH v5 1/5] cli: command line parsing: allow default for\r
+       keyword options\r
+In-Reply-To: <1338047694-32548-2-git-send-email-markwalters1009@gmail.com>\r
+References: <1338047694-32548-1-git-send-email-markwalters1009@gmail.com>\r
+       <1338047694-32548-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: Sun, 27 May 2012 02:33:02 -0000\r
+\r
+On Sat, 26 May 2012 16:54:50 +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 first possible argument is\r
+> chosen. This make it easier to add options to existing boolean\r
+> arguments (the existing --option can default to TRUE).\r
+\r
+This has the side-effect of allowing defaults for all keyword options,\r
+right?  I'm not sure that's desirable when the default is non-obvious.\r
+\r
+Maybe keyword options which allow an optional argument should have an\r
+explicit entry in the notmuch_keyword_t[] array, e.g. under "" or "default".\r
+\r
+> diff --git a/command-line-arguments.c b/command-line-arguments.c\r
+> index 76b185f..d40c7e6 100644\r
+> --- a/command-line-arguments.c\r
+> +++ b/command-line-arguments.c\r
+> @@ -11,10 +11,16 @@\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 so return first option as default */\r
+> +    *((int *)arg_desc->output_var) = keywords->value;\r
+> +    return TRUE;\r
+> +    }\r
+\r
+Indentation.\r
+\r
+Peter\r