aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Peter Wang <novalazy@gmail.com>2012-04-14 11:41:02 +1000
committerGravatar David Bremner <bremner@debian.org>2012-04-28 10:13:55 -0300
commit371f3b12a671e3bd955a5e589bd705e3d254d57b (patch)
treec705f02f7d99c7a861a015b73c5fbbe80e38167d
parent7bfc4bf501af2207123135065b08bd4874446de8 (diff)
config: Check 'config get' arity exactly
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.
-rw-r--r--notmuch-config.c19
1 files changed, 15 insertions, 4 deletions
diff --git a/notmuch-config.c b/notmuch-config.c
index 85fc7745..f9eb9778 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]);