mirror of
https://git.notmuchmail.org/git/notmuch
synced 2024-11-27 21:27:58 +01:00
cli: allow empty strings for notmuch insert --folder argument
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 commit is contained in:
parent
7ac96b149f
commit
733ccfabca
4 changed files with 7 additions and 3 deletions
|
@ -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);
|
fprintf (stderr, "Option \"%s\" needs a string argument.\n", arg_desc->name);
|
||||||
return false;
|
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);
|
fprintf (stderr, "String argument for option \"%s\" must be non-empty.\n", arg_desc->name);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,6 +32,9 @@ typedef struct notmuch_opt_desc {
|
||||||
/* Optional, if non-NULL, set to true if the option is present. */
|
/* Optional, if non-NULL, set to true if the option is present. */
|
||||||
bool *present;
|
bool *present;
|
||||||
|
|
||||||
|
/* Optional, allow empty strings for opt_string. */
|
||||||
|
bool allow_empty;
|
||||||
|
|
||||||
/* Must be set for opt_keyword and opt_flags. */
|
/* Must be set for opt_keyword and opt_flags. */
|
||||||
const struct notmuch_keyword *keywords;
|
const struct notmuch_keyword *keywords;
|
||||||
} notmuch_opt_desc_t;
|
} notmuch_opt_desc_t;
|
||||||
|
|
|
@ -34,7 +34,8 @@ Supported options for **insert** include
|
||||||
``--folder=<``\ folder\ **>**
|
``--folder=<``\ folder\ **>**
|
||||||
Deliver the message to the specified folder, relative to the
|
Deliver the message to the specified folder, relative to the
|
||||||
top-level directory given by the value of **database.path**. 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``
|
``--create-folder``
|
||||||
Try to create the folder named by the ``--folder`` option, if it
|
Try to create the folder named by the ``--folder`` option, if it
|
||||||
|
|
|
@ -464,7 +464,7 @@ notmuch_insert_command (notmuch_config_t *config, int argc, char *argv[])
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
|
|
||||||
notmuch_opt_desc_t options[] = {
|
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 = &create_folder, .name = "create-folder" },
|
||||||
{ .opt_bool = &keep, .name = "keep" },
|
{ .opt_bool = &keep, .name = "keep" },
|
||||||
{ .opt_bool = &no_hooks, .name = "no-hooks" },
|
{ .opt_bool = &no_hooks, .name = "no-hooks" },
|
||||||
|
|
Loading…
Reference in a new issue