unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* [PATCH] cli: allow empty strings for notmuch insert --folder argument
  2017-10-01 20:53 [PATCH v2 00/15] cli: argument parsing changes Jani Nikula
@ 2017-10-02 16:25 ` Jani Nikula
  0 siblings, 0 replies; 5+ messages in thread
From: Jani Nikula @ 2017-10-02 16:25 UTC (permalink / raw)
  To: notmuch; +Cc: jani, David Bremner, Daniel Kahn Gillmor

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

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

* [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] test: test notmuch insert --folder=""
  2017-10-14 13:15 [PATCH] cli: allow empty strings for notmuch insert --folder argument Jani Nikula
@ 2017-11-02 19:08 ` 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
  1 sibling, 1 reply; 5+ messages in thread
From: Jani Nikula @ 2017-11-02 19:08 UTC (permalink / raw)
  To: Jani Nikula, notmuch

Test insert into top level folder.
---
 test/T070-insert.sh | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/test/T070-insert.sh b/test/T070-insert.sh
index f1650e623e35..40519bb2f217 100755
--- a/test/T070-insert.sh
+++ b/test/T070-insert.sh
@@ -132,6 +132,13 @@ output=$(notmuch search --output=files path:Drafts/new)
 dirname=$(dirname "$output")
 test_expect_equal "$dirname" "$MAIL_DIR/Drafts/new"
 
+test_begin_subtest "Insert message into top level folder"
+gen_insert_msg
+notmuch insert --folder="" < "$gen_msg_filename"
+output=$(notmuch search --output=files id:${gen_msg_id})
+dirname=$(dirname "$output")
+test_expect_equal "$dirname" "$MAIL_DIR/new"
+
 test_begin_subtest "Insert message into folder with trailing /"
 gen_insert_msg
 notmuch insert --folder=Drafts/ < "$gen_msg_filename"
-- 
2.11.0

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

* Re: [PATCH] test: test notmuch insert --folder=""
  2017-11-02 19:08 ` [PATCH] test: test notmuch insert --folder="" Jani Nikula
@ 2017-11-02 20:24   ` Tomi Ollila
  0 siblings, 0 replies; 5+ messages in thread
From: Tomi Ollila @ 2017-11-02 20:24 UTC (permalink / raw)
  To: notmuch

On Thu, Nov 02 2017, Jani Nikula wrote:

I just wonder why our examples always use the format that is hardest to
write (these 3 being equivalent):

    --folder=""  requires shift-2:s pressed twice on my keyboard
    --folder=''  requires press '-key (w/o shift) (twice) on my keyboard
    --folder=    requires neither

  
That said, this change LGTM.

Tomi


> Test insert into top level folder.
> ---
>  test/T070-insert.sh | 7 +++++++
>  1 file changed, 7 insertions(+)
>
> diff --git a/test/T070-insert.sh b/test/T070-insert.sh
> index f1650e623e35..40519bb2f217 100755
> --- a/test/T070-insert.sh
> +++ b/test/T070-insert.sh
> @@ -132,6 +132,13 @@ output=$(notmuch search --output=files path:Drafts/new)
>  dirname=$(dirname "$output")
>  test_expect_equal "$dirname" "$MAIL_DIR/Drafts/new"
>  
> +test_begin_subtest "Insert message into top level folder"
> +gen_insert_msg
> +notmuch insert --folder="" < "$gen_msg_filename"
> +output=$(notmuch search --output=files id:${gen_msg_id})
> +dirname=$(dirname "$output")
> +test_expect_equal "$dirname" "$MAIL_DIR/new"
> +
>  test_begin_subtest "Insert message into folder with trailing /"
>  gen_insert_msg
>  notmuch insert --folder=Drafts/ < "$gen_msg_filename"
> -- 
> 2.11.0
>
> _______________________________________________
> notmuch mailing list
> notmuch@notmuchmail.org
> https://notmuchmail.org/mailman/listinfo/notmuch

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

* Re: [PATCH] cli: allow empty strings for notmuch insert --folder argument
  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-08 14:50 ` David Bremner
  1 sibling, 0 replies; 5+ messages in thread
From: David Bremner @ 2017-11-08 14:50 UTC (permalink / raw)
  To: Jani Nikula, notmuch

Jani Nikula <jani@nikula.org> writes:

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

Series pushed to master.

d

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