unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: Jani Nikula <jani@nikula.org>
To: notmuch@notmuchmail.org
Cc: jani@nikula.org, David Bremner <david@tethera.net>,
	Daniel Kahn Gillmor <dkg@fifthhorseman.net>
Subject: [PATCH] cli: allow empty strings for notmuch insert --folder argument
Date: Mon,  2 Oct 2017 19:25:52 +0300	[thread overview]
Message-ID: <20171002162552.4827-1-jani@nikula.org> (raw)
In-Reply-To: <cover.1506890421.git.jani@nikula.org>

Now that it's easy to add argument specific modifiers in opt
descriptions, add a new .allow_empty field to allow empty strings for
individual string arguments while retaining strict checks
elsewhere. Use this for notmuch insert --folder, where the empty
string means top level folder.

---

This patch addresses id:87y3owr22c.fsf@nikula.org

Depends on most of the series, but specifically not on the more
controversial patches 13-15.
---
 command-line-arguments.c    | 2 +-
 command-line-arguments.h    | 3 +++
 doc/man1/notmuch-insert.rst | 3 ++-
 notmuch-insert.c            | 2 +-
 4 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/command-line-arguments.c b/command-line-arguments.c
index 3fa8d9044966..b84bfe8168b5 100644
--- a/command-line-arguments.c
+++ b/command-line-arguments.c
@@ -81,7 +81,7 @@ _process_string_arg (const notmuch_opt_desc_t *arg_desc, char next, const char *
 	fprintf (stderr, "Option \"%s\" needs a string argument.\n", arg_desc->name);
 	return FALSE;
     }
-    if (arg_str[0] == '\0') {
+    if (arg_str[0] == '\0' && ! arg_desc->allow_empty) {
 	fprintf (stderr, "String argument for option \"%s\" must be non-empty.\n", arg_desc->name);
 	return FALSE;
     }
diff --git a/command-line-arguments.h b/command-line-arguments.h
index dfc808bdab78..04b04b939cba 100644
--- a/command-line-arguments.h
+++ b/command-line-arguments.h
@@ -30,6 +30,9 @@ typedef struct notmuch_opt_desc {
     /* Optional, if non-NULL, set to TRUE if the option is present. */
     notmuch_bool_t *present;
 
+    /* Optional, allow empty strings for opt_string. */
+    notmuch_bool_t allow_empty;
+
     /* Must be set for opt_keyword and opt_flags. */
     const struct notmuch_keyword *keywords;
 } notmuch_opt_desc_t;
diff --git a/doc/man1/notmuch-insert.rst b/doc/man1/notmuch-insert.rst
index f79600d6571f..2f2466a6588b 100644
--- a/doc/man1/notmuch-insert.rst
+++ b/doc/man1/notmuch-insert.rst
@@ -34,7 +34,8 @@ Supported options for **insert** include
     ``--folder=<``\ folder\ **>**
         Deliver the message to the specified folder, relative to the
         top-level directory given by the value of **database.path**. The
-        default is to deliver to the top-level directory.
+        default is the empty string, which means delivering to the
+        top-level directory.
 
     ``--create-folder``
         Try to create the folder named by the ``--folder`` option, if it
diff --git a/notmuch-insert.c b/notmuch-insert.c
index bbbc29ea103d..2758723ab2fb 100644
--- a/notmuch-insert.c
+++ b/notmuch-insert.c
@@ -463,7 +463,7 @@ notmuch_insert_command (notmuch_config_t *config, int argc, char *argv[])
     unsigned int i;
 
     notmuch_opt_desc_t options[] = {
-	{ .opt_string = &folder, .name = "folder" },
+	{ .opt_string = &folder, .name = "folder", .allow_empty = TRUE },
 	{ .opt_bool = &create_folder, .name = "create-folder" },
 	{ .opt_bool = &keep, .name = "keep" },
 	{ .opt_bool =  &no_hooks, .name = "no-hooks" },
-- 
2.11.0

  parent reply	other threads:[~2017-10-02 16:26 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-01 20:53 [PATCH v2 00/15] cli: argument parsing changes Jani Nikula
2017-10-01 20:53 ` [PATCH v2 01/15] cli: strip trailing "/" from the final maildir path in notmuch insert Jani Nikula
2017-10-01 20:53 ` [PATCH v2 02/15] cli: use designated initializers for opt desc Jani Nikula
2017-10-01 20:53 ` [PATCH v2 03/15] test: add boolean argument to arg-test Jani Nikula
2017-10-01 20:53 ` [PATCH v2 04/15] test: add opt_inherit " Jani Nikula
2017-10-01 20:53 ` [PATCH v2 05/15] cli: add .present field to opt desc to check if the arg was present Jani Nikula
2017-10-01 20:53 ` [PATCH v2 06/15] test: expand argument parsing tests Jani Nikula
2017-10-01 20:53 ` [PATCH v2 07/15] cli: use the arg parser .present feature to handle show --entire-thread Jani Nikula
2017-10-01 20:53 ` [PATCH v2 08/15] hex-xcode: use notmuch_bool_t for boolean arguments Jani Nikula
2017-10-01 20:53 ` [PATCH v2 09/15] cli: use notmuch_bool_t for boolean argument in show Jani Nikula
2017-10-01 20:53 ` [PATCH v2 10/15] cli: refactor boolean argument processing Jani Nikula
2017-10-01 20:53 ` [PATCH v2 11/15] cli: change while to for in keyword " Jani Nikula
2017-10-01 20:53 ` [PATCH v2 12/15] cli: reduce indent " Jani Nikula
2017-10-02  0:33   ` David Bremner
2017-10-05 10:43     ` David Bremner
2017-10-01 20:53 ` [PATCH v2 13/15] cli: add support for --no- prefixed boolean and keyword flag arguments Jani Nikula
2017-10-01 21:08   ` William Casarin
2017-10-02 15:52     ` Jani Nikula
2017-10-01 20:53 ` [PATCH v2 14/15] cli: use the negating boolean support for new and insert --no-hooks Jani Nikula
2017-10-01 20:53 ` [PATCH v2 15/15] test: expand argument parsing sanity checks Jani Nikula
2017-10-02 16:25 ` Jani Nikula [this message]
  -- strict thread matches above, loose matches on Subject: below --
2017-10-14 13:15 [PATCH] cli: allow empty strings for notmuch insert --folder argument Jani Nikula
2017-11-08 14:50 ` David Bremner

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=20171002162552.4827-1-jani@nikula.org \
    --to=jani@nikula.org \
    --cc=david@tethera.net \
    --cc=dkg@fifthhorseman.net \
    --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).