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 9929C431FBC for ; Mon, 3 Dec 2012 14:28:48 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -0.7 X-Spam-Level: X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5 tests=[RCVD_IN_DNSWL_LOW=-0.7] 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 PJQSSqbkpTsd for ; Mon, 3 Dec 2012 14:28:48 -0800 (PST) Received: from dmz-mailsec-scanner-8.mit.edu (DMZ-MAILSEC-SCANNER-8.MIT.EDU [18.7.68.37]) by olra.theworths.org (Postfix) with ESMTP id 048C7431FAE for ; Mon, 3 Dec 2012 14:28:47 -0800 (PST) X-AuditID: 12074425-b7f606d0000008ea-44-50bd279fa48e Received: from mailhub-auth-3.mit.edu ( [18.9.21.43]) by dmz-mailsec-scanner-8.mit.edu (Symantec Messaging Gateway) with SMTP id 1B.AA.02282.F972DB05; Mon, 3 Dec 2012 17:28:47 -0500 (EST) Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103]) by mailhub-auth-3.mit.edu (8.13.8/8.9.2) with ESMTP id qB3MSkBO032372; Mon, 3 Dec 2012 17:28:47 -0500 Received: from awakening.csail.mit.edu (awakening.csail.mit.edu [18.26.4.91]) (authenticated bits=0) (User authenticated as amdragon@ATHENA.MIT.EDU) by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id qB3MSi65014301 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NOT); Mon, 3 Dec 2012 17:28:46 -0500 (EST) Received: from amthrax by awakening.csail.mit.edu with local (Exim 4.80) (envelope-from ) id 1TfeVI-00047r-GZ; Mon, 03 Dec 2012 17:28:44 -0500 Date: Mon, 3 Dec 2012 17:28:44 -0500 From: Austin Clements To: Jani Nikula Subject: Re: [PATCH 2/2] cli: convert "notmuch new" to the argument parser Message-ID: <20121203222844.GH1020@mit.edu> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFmpmleLIzCtJLcpLzFFi42IR4hTV1p2vvjfAYOIrboum6c4W12/OZHZg 8rh1/zW7x7NVt5gDmKK4bFJSczLLUov07RK4MubsDS14JllxoecMawPjKeEuRk4OCQETiRWP XrFB2GISF+6tB7K5OIQE9jFKvNn9gwXCWc8osePJQkYI5wKTxN6V16DKljBKNH2ayQ7SzyKg InH74UEmEJtNQENi2/7ljCC2iICixOaT+8FsZgFpiW+/m8FqhAW8JI68OwW2m1dAW+LKslZ2 iKELGSUONnUwQiQEJU7OfMIC0awlcePfS6BmDrBBy/9xgIQ5BcIkzrdOBJspCnTDlJPb2CYw Cs1C0j0LSfcshO4FjMyrGGVTcqt0cxMzc4pTk3WLkxPz8lKLdC30cjNL9FJTSjcxgsKa3UV1 B+OEQ0qHGAU4GJV4eCfc2hMgxJpYVlyZe4hRkoNJSZRXSmJvgBBfUn5KZUZicUZ8UWlOavEh RgkOZiUR3tfsQDnelMTKqtSifJiUNAeLkjjvjZSb/kIC6YklqdmpqQWpRTBZGQ4OJQneOjWg RsGi1PTUirTMnBKENBMHJ8hwHqDhJSA1vMUFibnFmekQ+VOMilLivKwgCQGQREZpHlwvLO28 YhQHekWYVxSkigeYsuC6XwENZgIa/EJoN8jgkkSElFQDY7L3dZZm5v93b6hm3atRWjBj99dF onL/rk8x7dxQGVV713a/Jv8Dkw0f2jVfLsmQff0+UfQZQ9YF39L9aQz6OTueHN+nsEZeT2j6 duNtBQrPzu3pnzqlZ2kZ46oWS3d1x8JXEb+uXN6wzPvYxP/zulTkqqeF/pDSOWwapPK11/3A rtuG6mfnL1BiKc5INNRiLipOBABnzlOpFgMAAA== Cc: notmuch@notmuchmail.org 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: Mon, 03 Dec 2012 22:28:48 -0000 LGTM. One minor nit below, but feel free to ignore it. Quoth Jani Nikula on Dec 03 at 10:56 pm: > Use the notmuch argument parser to handle arguments in "notmuch > new". As a side effect, this fixes broken STRNCMP_LITERAL usage that > accepts, for example, --verbosefoo for --verbose. > --- > notmuch-new.c | 38 +++++++++++++++++++------------------- > 1 file changed, 19 insertions(+), 19 deletions(-) > > diff --git a/notmuch-new.c b/notmuch-new.c > index 718a538..feb9c32 100644 > --- a/notmuch-new.c > +++ b/notmuch-new.c > @@ -36,8 +36,8 @@ typedef struct _filename_list { > > typedef struct { > int output_is_a_tty; > - int verbose; > - int debug; > + notmuch_bool_t verbose; > + notmuch_bool_t debug; > const char **new_tags; > size_t new_tags_length; > const char **new_ignore; > @@ -853,28 +853,28 @@ notmuch_new_command (void *ctx, int argc, char *argv[]) > char *dot_notmuch_path; > struct sigaction action; > _filename_node_t *f; > + int opt_index; > int i; > notmuch_bool_t timer_is_active = FALSE; > - notmuch_bool_t run_hooks = TRUE; > + notmuch_bool_t no_hooks = FALSE; > > - add_files_state.verbose = 0; > - add_files_state.debug = 0; > + add_files_state.verbose = FALSE; > + add_files_state.debug = FALSE; > add_files_state.output_is_a_tty = isatty (fileno (stdout)); > > - argc--; argv++; /* skip subcommand argument */ > + notmuch_opt_desc_t options[] = { > + { NOTMUCH_OPT_BOOLEAN, &add_files_state.verbose, "verbose", 'v', 0 }, > + { NOTMUCH_OPT_BOOLEAN, &add_files_state.debug, "debug", 'd', 0 }, > + { NOTMUCH_OPT_BOOLEAN, &no_hooks, "no-hooks", 'n', 0 }, Not that the single character arguments matter right now, but '-n' is often used for "dry-run", which could actually apply to notmuch new. > + { 0, 0, 0, 0, 0 } > + }; > > - for (i = 0; i < argc && argv[i][0] == '-'; i++) { > - if (STRNCMP_LITERAL (argv[i], "--verbose") == 0) { > - add_files_state.verbose = 1; > - } else if (strcmp (argv[i], "--debug") == 0) { > - add_files_state.debug = 1; > - } else if (strcmp (argv[i], "--no-hooks") == 0) { > - run_hooks = FALSE; > - } else { > - fprintf (stderr, "Unrecognized option: %s\n", argv[i]); > - return 1; > - } > + opt_index = parse_arguments (argc, argv, options, 1); > + if (opt_index < 0) { > + /* diagnostics already printed */ > + return 1; > } > + > config = notmuch_config_open (ctx, NULL, NULL); > if (config == NULL) > return 1; > @@ -884,7 +884,7 @@ notmuch_new_command (void *ctx, int argc, char *argv[]) > add_files_state.synchronize_flags = notmuch_config_get_maildir_synchronize_flags (config); > db_path = notmuch_config_get_database_path (config); > > - if (run_hooks) { > + if (!no_hooks) { > ret = notmuch_run_hook (db_path, "pre-new"); > if (ret) > return ret; > @@ -1045,7 +1045,7 @@ notmuch_new_command (void *ctx, int argc, char *argv[]) > > notmuch_database_destroy (notmuch); > > - if (run_hooks && !ret && !interrupted) > + if (!no_hooks && !ret && !interrupted) > ret = notmuch_run_hook (db_path, "post-new"); > > return ret || interrupted;