unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: Jani Nikula <jani@nikula.org>
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	[thread overview]
Message-ID: <61518702fe578babfae49cd2098a996dc6759efe.1331329406.git.jani@nikula.org> (raw)
In-Reply-To: <cover.1331329406.git.jani@nikula.org>
In-Reply-To: <cover.1331329406.git.jani@nikula.org>

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 <jani@nikula.org>
---
 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

  parent reply	other threads:[~2012-03-09 22:33 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-03-08 22:15 [PATCH 0/2] cli: Parsing. Add option NOTMUCH_OPT_INT_OR_BOOLEAN Mark Walters
2012-03-08 22:15 ` [PATCH 1/2] " Mark Walters
2012-03-08 22:15 ` [PATCH 2/2] cli: make --entire-thread option notmuch-show.c INT_OR_BOOLEAN Mark Walters
2012-03-09  0:48 ` [PATCH 0/2] cli: Parsing. Add option NOTMUCH_OPT_INT_OR_BOOLEAN Jani Nikula
2012-03-09  5:11   ` Mark Walters
2012-03-09 22:33     ` [PATCH 0/3] argument parsing additions Jani Nikula
2012-03-09 22:33       ` [PATCH 1/3] command-line-arguments: allow true and false keywords for booleans Jani Nikula
2012-03-09 22:33       ` Jani Nikula [this message]
2012-03-09 22:33       ` [PATCH 3/3] cli: allow switching off entire thread mode in notmuch show json format Jani Nikula
2012-03-10 11:23       ` [PATCH 0/3] argument parsing additions Mark Walters
2012-03-11 19:26         ` Jani Nikula

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://notmuchmail.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=61518702fe578babfae49cd2098a996dc6759efe.1331329406.git.jani@nikula.org \
    --to=jani@nikula.org \
    --cc=markwalters1009@gmail.com \
    --cc=notmuch@notmuchmail.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).