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 C2581431FD9 for ; Fri, 9 Mar 2012 14:33:46 -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 lidQAWwVhZKb for ; Fri, 9 Mar 2012 14:33:45 -0800 (PST) Received: from mail-lpp01m010-f53.google.com (mail-lpp01m010-f53.google.com [209.85.215.53]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id E7DF8431FC3 for ; Fri, 9 Mar 2012 14:33:41 -0800 (PST) Received: by mail-lpp01m010-f53.google.com with SMTP id c1so2252374lah.26 for ; Fri, 09 Mar 2012 14:33:41 -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=6qzoLyJoPQFeHfB/mPvQtx1WiF85SdzYS1GQpO0CbbY=; b=SB+pykOm+HUiDWzmpCCG3cFkRaG30y2ViAmiyPc877Tc+d6PmLsB0064UNV4sr9VW5 BHbhEwDdQOYM5G8byGqa0Le0MUho84I9x0NxsUq28GhZ4aCrMWzngbonPibVQMZ3EyMp r3E1k08TPxSjbhtogBeeZhdfT7oeMbgwFhW2RFs37AyrNijjPYxWRZ/XeWL19AeiJMsc g1CpWNqaimpT0YNPzBnZy9p6mX9manjQOWdeig+/OHUZmuSE1oy2uEBE+/TJT3H1SAgK //hgk8GWZQ+2U02Ldpu0zmDHIyshoy8JtUdgy6+SWtL5POxsFJBxG2RVyLeqxIih6fZY NfpQ== Received: by 10.112.29.34 with SMTP id g2mr1538610lbh.40.1331332421524; Fri, 09 Mar 2012 14:33:41 -0800 (PST) Received: from localhost (dsl-hkibrasgw4-fe50f800-253.dhcp.inet.fi. [84.248.80.253]) by mx.google.com with ESMTPS id mf3sm5903748lab.1.2012.03.09.14.33.39 (version=SSLv3 cipher=OTHER); Fri, 09 Mar 2012 14:33:40 -0800 (PST) From: Jani Nikula To: notmuch@notmuchmail.org, markwalters1009@gmail.com Subject: [PATCH 2/3] command-line-arguments: support keyword arguments with default value Date: Sat, 10 Mar 2012 00:33:29 +0200 Message-Id: <61518702fe578babfae49cd2098a996dc6759efe.1331329406.git.jani@nikula.org> X-Mailer: git-send-email 1.7.5.4 In-Reply-To: References: <87399iicit.fsf@qmul.ac.uk> In-Reply-To: References: X-Gm-Message-State: ALoCoQmhagjEzf4Cp+r1fhAmGsAawHGjagB6MsJ99q7lzgXnU82eCVVmBOSaupmk9cv31xdVmast 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: Fri, 09 Mar 2012 22:33:47 -0000 Add NOTMUCH_OPT_KEYWORD_DEFAULT to support plain --arg in addition to --arg=value. The value to use is the first in the list of keywords. Signed-off-by: Jani Nikula --- command-line-arguments.c | 11 ++++++++++- command-line-arguments.h | 1 + 2 files changed, 11 insertions(+), 1 deletions(-) diff --git a/command-line-arguments.c b/command-line-arguments.c index 1bdb881..2a3646f 100644 --- a/command-line-arguments.c +++ b/command-line-arguments.c @@ -15,6 +15,13 @@ _process_keyword_arg (const notmuch_opt_desc_t *arg_desc, const char *arg_str) { const notmuch_keyword_t *keywords = arg_desc->keywords; + if (arg_str == NULL) { + /* no keyword specified, use the first keyword as default */ + if (arg_desc->output_var) + *((int *)arg_desc->output_var) = keywords->value; + return TRUE; + } + while (keywords->name) { if (strcmp (arg_str, keywords->name) == 0) { if (arg_desc->output_var) { @@ -105,7 +112,8 @@ parse_option (const char *arg, return FALSE; } else if (next == '\0') { value = NULL; - if (try->opt_type != NOTMUCH_OPT_BOOLEAN) + if (try->opt_type != NOTMUCH_OPT_BOOLEAN && + try->opt_type != NOTMUCH_OPT_KEYWORD_DEFAULT) return FALSE; } else { return FALSE; @@ -116,6 +124,7 @@ parse_option (const char *arg, switch (try->opt_type) { case NOTMUCH_OPT_KEYWORD: + case NOTMUCH_OPT_KEYWORD_DEFAULT: return _process_keyword_arg (try, value); break; case NOTMUCH_OPT_BOOLEAN: diff --git a/command-line-arguments.h b/command-line-arguments.h index de1734a..d70c84c 100644 --- a/command-line-arguments.h +++ b/command-line-arguments.h @@ -8,6 +8,7 @@ enum notmuch_opt_type { NOTMUCH_OPT_BOOLEAN, /* --verbose */ NOTMUCH_OPT_INT, /* --frob=8 */ NOTMUCH_OPT_KEYWORD, /* --format=raw|json|text */ + NOTMUCH_OPT_KEYWORD_DEFAULT,/* --format[=raw|json] */ NOTMUCH_OPT_STRING, /* --file=/tmp/gnarf.txt */ NOTMUCH_OPT_POSITION /* notmuch dump pos_arg */ }; -- 1.7.5.4