From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id 468C4431FC2 for ; Mon, 3 Dec 2012 12:56:24 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References" 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 Yo1m3Mo5gv9B for ; Mon, 3 Dec 2012 12:56:23 -0800 (PST) Received: from mail-lb0-f181.google.com (mail-lb0-f181.google.com [209.85.217.181]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id D7261431FB6 for ; Mon, 3 Dec 2012 12:56:22 -0800 (PST) Received: by mail-lb0-f181.google.com with SMTP id ge1so2880376lbb.26 for ; Mon, 03 Dec 2012 12:56:21 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references :in-reply-to:references:x-gm-message-state; bh=WjieLvL5Vvd+DqOJBp48Ahgr3TtkaU0A1c8O5KtgoNw=; b=PPYyYFc2jVtb5UYSbao7TPoyQ7Hj2DNcnkTGrOXJETp7BSxRGnlqofDoqnU34trzEx h4h8SZnBQCIoDsrx8Q8Ifhzf0G23/XJRjeoGF72sHCQmpirrf6lK0BZsBDeWTylNfYlj 7cbSXPwtKsLqwsYQ7fu3/dGd5DDqwESCLcXNwP6VSqtl0UiPFDJXQSaJa5t290xaMa3W 1OVOCtS3Q5aMOy4XvSVkm6iFGch+ObsZIkINip/9gzdKACVuO+hutIwUnw/Dxa8/Pk+9 4lrN82ipBKt2GXAKt/bAScMzpdlYSHOdGC/cLPRoQWkgcgjyrZK455yGxdIu0Sspd9zM BCrg== Received: by 10.152.124.111 with SMTP id mh15mr10745675lab.20.1354568181018; Mon, 03 Dec 2012 12:56:21 -0800 (PST) Received: from localhost (dsl-hkibrasgw4-fe51df00-27.dhcp.inet.fi. [80.223.81.27]) by mx.google.com with ESMTPS id oj5sm5824688lab.8.2012.12.03.12.56.19 (version=SSLv3 cipher=OTHER); Mon, 03 Dec 2012 12:56:20 -0800 (PST) From: Jani Nikula To: notmuch@notmuchmail.org Subject: [PATCH 2/2] cli: convert "notmuch new" to the argument parser Date: Mon, 3 Dec 2012 22:56:13 +0200 Message-Id: X-Mailer: git-send-email 1.7.10.4 In-Reply-To: References: In-Reply-To: References: X-Gm-Message-State: ALoCoQlRUscPPEoj3fx6iEattPNM0qaNTLfIQi5m5rCg3+1SIq1luy50k2cJWlIoiIY0C0DoB2xj 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 20:56:24 -0000 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 }, + { 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; -- 1.7.10.4