[PATCH v4 2/6] config: Check 'config get' arity exactly
Peter Wang
novalazy at gmail.com
Fri Apr 13 18:41:02 PDT 2012
Require that 'config get' is passed exactly one additional argument,
instead of silently ignoring extra arguments. As a side-effect, produce
more specific error messages for the 'config' command as a whole.
---
notmuch-config.c | 19 +++++++++++++++----
1 files changed, 15 insertions(+), 4 deletions(-)
diff --git a/notmuch-config.c b/notmuch-config.c
index 85fc774..f9eb977 100644
--- a/notmuch-config.c
+++ b/notmuch-config.c
@@ -804,15 +804,26 @@ notmuch_config_command (void *ctx, int argc, char *argv[])
{
argc--; argv++; /* skip subcommand argument */
- if (argc < 2) {
- fprintf (stderr, "Error: notmuch config requires at least two arguments.\n");
+ if (argc < 1) {
+ fprintf (stderr, "Error: notmuch config requires at least one argument.\n");
return 1;
}
- if (strcmp (argv[0], "get") == 0)
+ if (strcmp (argv[0], "get") == 0) {
+ if (argc != 2) {
+ fprintf (stderr, "Error: notmuch config get requires exactly "
+ "one argument.\n");
+ return 1;
+ }
return notmuch_config_command_get (ctx, argv[1]);
- else if (strcmp (argv[0], "set") == 0)
+ } else if (strcmp (argv[0], "set") == 0) {
+ if (argc < 2) {
+ fprintf (stderr, "Error: notmuch config set requires at least "
+ "one argument.\n");
+ return 1;
+ }
return notmuch_config_command_set (ctx, argv[1], argc - 2, argv + 2);
+ }
fprintf (stderr, "Unrecognized argument for notmuch config: %s\n",
argv[0]);
--
1.7.4.4
More information about the notmuch
mailing list