From 61f0a5b8ee2adf540106a09c5f83fe634da6beb3 Mon Sep 17 00:00:00 2001 From: David Bremner Date: Fri, 21 Oct 2011 09:19:17 -0300 Subject: cli: change argument parsing convention for subcommands previously we deleted the subcommand name from argv before passing to the subcommand. In this version, the deletion is done in the actual subcommands. Although this causes some duplication of code, it allows us to be more flexible about how we parse command line arguments in the subcommand, including possibly using off-the-shelf routines like getopt_long that expect the name of the command in argv[0]. --- notmuch.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'notmuch.c') diff --git a/notmuch.c b/notmuch.c index 640ad8da..4232bee7 100644 --- a/notmuch.c +++ b/notmuch.c @@ -465,6 +465,8 @@ notmuch_help_command (unused (void *ctx), int argc, char *argv[]) command_t *command; unsigned int i; + argc--; argv++; /* Ignore "help" */ + if (argc == 0) { printf ("The notmuch mail system.\n\n"); usage (stdout); @@ -639,7 +641,7 @@ main (int argc, char *argv[]) command = &commands[i]; if (strcmp (argv[1], command->name) == 0) - return (command->function) (local, argc - 2, &argv[2]); + return (command->function) (local, argc - 1, &argv[1]); } fprintf (stderr, "Error: Unknown command '%s' (see \"notmuch help\")\n", -- cgit v1.2.3