From: Mark Walters Date: Tue, 7 Apr 2015 07:22:50 +0000 (+0100) Subject: Re: [Patch v2 3/4] cli: define shared options, use for --help and --version X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=e61c42229a8c74fb2d25716d383b42ca691a9c1d;p=notmuch-archives.git Re: [Patch v2 3/4] cli: define shared options, use for --help and --version --- diff --git a/77/75dece3b169894aac142197e498983b6955545 b/77/75dece3b169894aac142197e498983b6955545 new file mode 100644 index 000000000..79260aca9 --- /dev/null +++ b/77/75dece3b169894aac142197e498983b6955545 @@ -0,0 +1,166 @@ +Return-Path: +X-Original-To: notmuch@notmuchmail.org +Delivered-To: notmuch@notmuchmail.org +Received: from localhost (localhost [127.0.0.1]) + by arlo.cworth.org (Postfix) with ESMTP id 3055E6DE1983 + for ; Tue, 7 Apr 2015 00:23:04 -0700 (PDT) +X-Virus-Scanned: Debian amavisd-new at cworth.org +X-Spam-Flag: NO +X-Spam-Score: -1.492 +X-Spam-Level: +X-Spam-Status: No, score=-1.492 tagged_above=-999 required=5 tests=[AWL=0.156, + DKIM_ADSP_CUSTOM_MED=0.001, FREEMAIL_FROM=0.001, NML_ADSP_CUSTOM_MED=1.2, + RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, + RP_MATCHES_RCVD=-0.55, T_FREEMAIL_FORGED_FROMDOMAIN=0.01, + T_HEADER_FROM_DIFFERENT_DOMAINS=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 gi-WQHLloL3p for ; + Tue, 7 Apr 2015 00:23:02 -0700 (PDT) +Received: from mail2.qmul.ac.uk (mail2.qmul.ac.uk [138.37.6.6]) + by arlo.cworth.org (Postfix) with ESMTPS id DA6916DE1974 + for ; Tue, 7 Apr 2015 00:23:01 -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 1YfNqb-0005ql-Gl; Tue, 07 Apr 2015 08:22:57 +0100 +Received: from 188.29.19.158.threembb.co.uk ([188.29.19.158] helo=localhost) + by smtp.qmul.ac.uk with esmtpsa (TLSv1:AES128-SHA:128) (Exim 4.71) + (envelope-from ) + id 1YfNqa-0006zr-Bv; Tue, 07 Apr 2015 08:22:57 +0100 +From: Mark Walters +To: David Bremner , David Bremner , + notmuch@notmuchmail.org +Subject: Re: [Patch v2 3/4] cli: define shared options, + use for --help and --version +In-Reply-To: <1428322958-2887-4-git-send-email-david@tethera.net> +References: <87d23ixnr7.fsf@maritornes.cs.unb.ca> + <1428322958-2887-1-git-send-email-david@tethera.net> + <1428322958-2887-4-git-send-email-david@tethera.net> +User-Agent: Notmuch/0.18.1+86~gef5e66a (http://notmuchmail.org) Emacs/23.4.1 + (x86_64-pc-linux-gnu) +Date: Tue, 07 Apr 2015 08:22:50 +0100 +Message-ID: <87y4m4qu5x.fsf@qmul.ac.uk> +MIME-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +X-QM-SPAM-Info: 188.29.19.158 is in Janet mirror of Spamhaus XBL; + see http://www.spamhaus.org/xbl/ +X-Sender-Host-Address: 188.29.19.158 +X-QM-Geographic: According to ripencc, + this message was delivered by a machine in Britain (UK) (GB). +X-QM-SPAM-Info: Sender has good ham record. :) +X-QM-Body-MD5: 420765bb4dc25d03f3d2e0ecd0cc0485 (of first 20000 bytes) +X-SpamAssassin-Score: -0.1 +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 -0.1 points. + Summary of the scoring: + * 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.1 AWL AWL: Adjusted score from AWL reputation of From: address +X-QM-Scan-Virus: ClamAV says the message is clean +X-BeenThere: notmuch@notmuchmail.org +X-Mailman-Version: 2.1.18 +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, 07 Apr 2015 07:23:04 -0000 + + +Hi + +> +void notmuch_process_shared_options (const char* help_name); +> diff --git a/notmuch.c b/notmuch.c + +> +/* any subcommand wanting to support these options should call +> + * inherit notmuch_shared_options and call +> + * notmuch_process_shared_options (subcommand_name); +> + */ +> +void +> +notmuch_process_shared_options (const char *help_name) { + +Perhaps call the argument something else as it might be used by other +commands later? Eg subcommand_name? (and in notmuch-client.h too) + +Best wishes + +Mark + + + + +> + if (print_version) { +> + printf ("notmuch " STRINGIFY(NOTMUCH_VERSION) "\n"); +> + exit (EXIT_SUCCESS); +> + } +> + +> + if (print_help) { +> + int ret = _help_for (help_name); +> + exit (ret); +> + } +> +} +> + +> + +> static command_t commands[] = { +> { NULL, notmuch_command, TRUE, +> "Notmuch main command." }, +> @@ -295,14 +324,12 @@ main (int argc, char *argv[]) +> command_t *command; +> char *config_file_name = NULL; +> notmuch_config_t *config = NULL; +> - notmuch_bool_t print_help=FALSE, print_version=FALSE; +> int opt_index; +> int ret; +> +> notmuch_opt_desc_t options[] = { +> - { NOTMUCH_OPT_BOOLEAN, &print_help, "help", 'h', 0 }, +> - { NOTMUCH_OPT_BOOLEAN, &print_version, "version", 'v', 0 }, +> { NOTMUCH_OPT_STRING, &config_file_name, "config", 'c', 0 }, +> + { NOTMUCH_OPT_INHERIT, (void *) ¬much_shared_options, NULL, 0, 0 }, +> { 0, 0, 0, 0, 0 } +> }; +> +> @@ -324,24 +351,7 @@ main (int argc, char *argv[]) +> goto DONE; +> } +> +> - /* Handle notmuch --help [command] and notmuch command --help. */ +> - if (print_help || +> - (opt_index + 1 < argc && strcmp (argv[opt_index + 1], "--help") == 0)) { +> - /* +> - * Pass the first positional argument as argv[1] so the help +> - * command can give help for it. The help command ignores the +> - * argv[0] passed to it. +> - */ +> - ret = notmuch_help_command (NULL, argc - opt_index + 1, +> - argv + opt_index - 1); +> - goto DONE; +> - } +> - +> - if (print_version) { +> - printf ("notmuch " STRINGIFY(NOTMUCH_VERSION) "\n"); +> - ret = EXIT_SUCCESS; +> - goto DONE; +> - } +> + notmuch_process_shared_options (NULL); +> +> if (opt_index < argc) +> command_name = argv[opt_index]; +> -- +> 2.1.4 +> +> _______________________________________________ +> notmuch mailing list +> notmuch@notmuchmail.org +> http://notmuchmail.org/mailman/listinfo/notmuch