unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* [PATCH] cli: allow empty strings for notmuch insert --folder argument
@ 2017-10-14 13:15 Jani Nikula
  2017-11-02 19:08 ` [PATCH] test: test notmuch insert --folder="" Jani Nikula
  2017-11-08 14:50 ` [PATCH] cli: allow empty strings for notmuch insert --folder argument David Bremner
  0 siblings, 2 replies; 5+ messages in thread
From: Jani Nikula @ 2017-10-14 13:15 UTC (permalink / raw)
  To: notmuch

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
---
 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 1ff5aae578c6..db73ca5efb89 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 76ca4dcbb276..c0228f7cb634 100644
--- a/command-line-arguments.h
+++ b/command-line-arguments.h
@@ -32,6 +32,9 @@ typedef struct notmuch_opt_desc {
     /* Optional, if non-NULL, set to true if the option is present. */
     bool *present;
 
+    /* Optional, allow empty strings for opt_string. */
+    bool 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 32be74193472..cff74731aaaa 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

^ permalink raw reply related	[flat|nested] 5+ messages in thread
* [PATCH v2 00/15] cli: argument parsing changes
@ 2017-10-01 20:53 Jani Nikula
  2017-10-02 16:25 ` [PATCH] cli: allow empty strings for notmuch insert --folder argument Jani Nikula
  0 siblings, 1 reply; 5+ messages in thread
From: Jani Nikula @ 2017-10-01 20:53 UTC (permalink / raw)
  To: notmuch; +Cc: jani, David Bremner, Daniel Kahn Gillmor

This series combines the designated initializers for argument parsing
from id:20170930213239.15392-1-jani@nikula.org and the argument parsing
refactoring from id:cover.1505853159.git.jani@nikula.org.

Additionally patch 1 handles some const confusion in notmuch-insert
before it becomes a problem in patch 2, and patches 5-7 add support for
the .present field to opt desc discussed in
id:87lgkvrhpa.fsf@nikula.org. Some more tests are sprinkled here and
there too.

BR,
Jani.


Jani Nikula (15):
  cli: strip trailing "/" from the final maildir path in notmuch insert
  cli: use designated initializers for opt desc
  test: add boolean argument to arg-test
  test: add opt_inherit to arg-test
  cli: add .present field to opt desc to check if the arg was present
  test: expand argument parsing tests
  cli: use the arg parser .present feature to handle show
    --entire-thread
  hex-xcode: use notmuch_bool_t for boolean arguments
  cli: use notmuch_bool_t for boolean argument in show
  cli: refactor boolean argument processing
  cli: change while to for in keyword argument processing
  cli: reduce indent in keyword argument processing
  cli: add support for --no- prefixed boolean and keyword flag arguments
  cli: use the negating boolean support for new and insert --no-hooks
  test: expand argument parsing sanity checks

 command-line-arguments.c      | 174 ++++++++++++++++++++++++++----------------
 command-line-arguments.h      |  41 ++++------
 notmuch-client.h              |   2 +-
 notmuch-compact.c             |   8 +-
 notmuch-count.c               |  16 ++--
 notmuch-dump.c                |  14 ++--
 notmuch-insert.c              |  48 ++++++------
 notmuch-new.c                 |  18 ++---
 notmuch-reindex.c             |   4 +-
 notmuch-reply.c               |  12 +--
 notmuch-restore.c             |  14 ++--
 notmuch-search.c              |  46 +++++------
 notmuch-show.c                |  41 +++++-----
 notmuch-tag.c                 |  12 +--
 notmuch.c                     |  22 +++---
 test/T410-argument-parsing.sh |  53 ++++++++++++-
 test/arg-test.c               |  56 +++++++++-----
 test/hex-xcode.c              |  12 +--
 test/random-corpus.c          |  20 ++---
 19 files changed, 350 insertions(+), 263 deletions(-)

-- 
2.11.0

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2017-11-08 14:50 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-10-14 13:15 [PATCH] cli: allow empty strings for notmuch insert --folder argument Jani Nikula
2017-11-02 19:08 ` [PATCH] test: test notmuch insert --folder="" Jani Nikula
2017-11-02 20:24   ` Tomi Ollila
2017-11-08 14:50 ` [PATCH] cli: allow empty strings for notmuch insert --folder argument David Bremner
  -- strict thread matches above, loose matches on Subject: below --
2017-10-01 20:53 [PATCH v2 00/15] cli: argument parsing changes Jani Nikula
2017-10-02 16:25 ` [PATCH] cli: allow empty strings for notmuch insert --folder argument Jani Nikula

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).