From: Mark Walters Date: Tue, 5 Jun 2012 14:34:19 +0000 (+0100) Subject: Re: [PATCH] cli: make the command line parser's errors more informative. X-Git-Url: http://git.tremily.us/gitweb.cgi?a=commitdiff_plain;h=d61ef6c3109a8a3e237cf6463c6a59311e7a9db6;p=notmuch-archives.git Re: [PATCH] cli: make the command line parser's errors more informative. --- diff --git a/2f/daf00aff5424ae7b22c8852f0699624c86d714 b/2f/daf00aff5424ae7b22c8852f0699624c86d714 new file mode 100644 index 000000000..df78234a3 --- /dev/null +++ b/2f/daf00aff5424ae7b22c8852f0699624c86d714 @@ -0,0 +1,146 @@ +Return-Path: +X-Original-To: notmuch@notmuchmail.org +Delivered-To: notmuch@notmuchmail.org +Received: from localhost (localhost [127.0.0.1]) + by olra.theworths.org (Postfix) with ESMTP id F089E431FAF + for ; Tue, 5 Jun 2012 07:34:21 -0700 (PDT) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Spam-Flag: NO +X-Spam-Score: -1.098 +X-Spam-Level: +X-Spam-Status: No, score=-1.098 tagged_above=-999 required=5 + tests=[DKIM_ADSP_CUSTOM_MED=0.001, FREEMAIL_FROM=0.001, + NML_ADSP_CUSTOM_MED=1.2, RCVD_IN_DNSWL_MED=-2.3] autolearn=disabled +Received: from olra.theworths.org ([127.0.0.1]) + by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) + with ESMTP id 338a2AplJeSk for ; + Tue, 5 Jun 2012 07:34:21 -0700 (PDT) +Received: from mail2.qmul.ac.uk (mail2.qmul.ac.uk [138.37.6.6]) + (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) + (No client certificate requested) + by olra.theworths.org (Postfix) with ESMTPS id 4CFDB431FAE + for ; Tue, 5 Jun 2012 07:34:21 -0700 (PDT) +Received: from smtp.qmul.ac.uk ([138.37.6.40]) + by mail2.qmul.ac.uk with esmtp (Exim 4.71) + (envelope-from ) + id 1Sbupt-00063f-9m; Tue, 05 Jun 2012 15:34:17 +0100 +Received: from 94-192-233-223.zone6.bethere.co.uk ([94.192.233.223] + helo=localhost) + by smtp.qmul.ac.uk with esmtpsa (TLSv1:AES128-SHA:128) (Exim 4.69) + (envelope-from ) + id 1Sbups-0007lf-Vv; Tue, 05 Jun 2012 15:34:17 +0100 +From: Mark Walters +To: Peter Wang , notmuch@notmuchmail.org +Subject: Re: [PATCH] cli: make the command line parser's errors more + informative. +In-Reply-To: <20120605184037.GB14297@hili.localdomain> +References: <1338723972-13063-1-git-send-email-markwalters1009@gmail.com> + <1338724128-13158-1-git-send-email-markwalters1009@gmail.com> + <20120605184037.GB14297@hili.localdomain> +User-Agent: Notmuch/0.13+55~g992aa73 (http://notmuchmail.org) Emacs/23.3.1 + (x86_64-pc-linux-gnu) +Date: Tue, 05 Jun 2012 15:34:19 +0100 +Message-ID: <87oboxakus.fsf@qmul.ac.uk> +MIME-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +X-Sender-Host-Address: 94.192.233.223 +X-QM-SPAM-Info: Sender has good ham record. :) +X-QM-Body-MD5: a79baf0f0899e319b14bb1c657376935 (of first 20000 bytes) +X-SpamAssassin-Score: -1.8 +X-SpamAssassin-SpamBar: - +X-SpamAssassin-Report: The QM spam filters have analysed this message to + determine if it is + spam. We require at least 5.0 points to mark a message as spam. + This message scored -1.8 points. + Summary of the scoring: + * -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at http://www.dnswl.org/, + * medium trust + * [138.37.6.40 listed in list.dnswl.org] + * 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail + provider * (markwalters1009[at]gmail.com) + * -0.0 T_RP_MATCHES_RCVD Envelope sender domain matches handover relay + * domain + * 0.5 AWL AWL: From: address is in the auto white-list +X-QM-Scan-Virus: ClamAV says the message is clean +X-BeenThere: notmuch@notmuchmail.org +X-Mailman-Version: 2.1.13 +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: Tue, 05 Jun 2012 14:34:22 -0000 + + +On Tue, 05 Jun 2012, Peter Wang wrote: +> On Sun, 3 Jun 2012 12:48:48 +0100, Mark Walters wrote: +>> +>> +static notmuch_bool_t +>> +_process_int_arg (const notmuch_opt_desc_t *arg_desc, char next, const char *arg_str) { +>> + +>> + char *endptr; +>> + if (next == 0 || arg_str[0] == 0) { +>> + fprintf (stderr, "Option \"%s\" needs an integer argument.\n", arg_desc->name); +>> + return FALSE; +>> + } +>> + +>> + *((int *)arg_desc->output_var) = strtol (arg_str, &endptr, 10); +>> + if (*endptr == 0) +>> + return TRUE; +> +> It's usually clearer to write '\0' for the null character. + +Yes I agree: fixed. I also changed the other instances. + +>> @@ -99,20 +133,13 @@ parse_option (const char *arg, +>> char next = arg[strlen (try->name)]; +>> const char *value= arg+strlen(try->name)+1; +>> +>> - char *endptr; +>> - +>> - /* Everything but boolean arguments (switches) needs a +>> - * delimiter, and a non-zero length value. Boolean +>> - * arguments may take an optional =true or =false value. +>> - */ +>> - if (next != '=' && next != ':' && next != 0) return FALSE; +>> - if (next == 0) { +>> - if (try->opt_type != NOTMUCH_OPT_BOOLEAN && +>> - try->opt_type != NOTMUCH_OPT_KEYWORD) +>> - return FALSE; +>> - } else { +>> - if (value[0] == 0) return FALSE; +>> - } +>> + /* If this is not the end of the argument (i.e. the next +>> + * character is not a space or a delimiter) we stop +>> + * parsing for this option but allow the parsing to +>> + * continue to for other options. This should allow +>> + * options to be initial segments of other options. */ +> +> It took me a little while to figure out what the last sentence was +> about. Perhaps: +> +> If we have not reached the end of the argument (i.e. the next +> character is not a space or delimiter) then the argument could +> still match a longer option name later in the option table. + +This is much clearer, thanks! + +> (otherwise, "continue to for other") +> +>> + if (next != '=' && next != ':' && next != 0) +>> + goto DONE_THIS_OPTION; +> +> The `goto' could be expressed as a `continue' in a `for' loop, AFAICS. + +This is also much nicer. Updated patch follows + +Thanks for the review! + +Best wishes + +Mark