]> git.cworth.org Git - notmuch/commitdiff
cli: allow empty strings for notmuch insert --folder argument
authorJani Nikula <jani@nikula.org>
Sat, 14 Oct 2017 13:15:43 +0000 (16:15 +0300)
committerDavid Bremner <david@tethera.net>
Wed, 8 Nov 2017 14:46:44 +0000 (09:46 -0500)
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.

command-line-arguments.c
command-line-arguments.h
doc/man1/notmuch-insert.rst
notmuch-insert.c

index 1ff5aae578c651a0b780fa00bcbd2c49dd3963b1..db73ca5efb896aaafbbe1b8a85437e20ba431b4f 100644 (file)
@@ -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;
     }
index 76ca4dcbb276714a15b8524fbe106ffd6ba2fc78..c0228f7cb634dca5f34182a53e40d0803dc644c5 100644 (file)
@@ -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;
index e2bf37d04c79e49f6a8127bf36949a84470d2f86..c500b251b571546a9c7ac8548c92405d3a328c58 100644 (file)
@@ -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
index 4d6b0a7fba2feb66d7d8ae3de5ca77cf5aa0bfce..bb835ba97517eef910406cabf0421e2a394ff574 100644 (file)
@@ -464,7 +464,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" },