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].
int
notmuch_config_command (void *ctx, int argc, char *argv[])
{
int
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");
return 1;
if (argc < 2) {
fprintf (stderr, "Error: notmuch config requires at least two arguments.\n");
return 1;
notmuch_sort_t sort = NOTMUCH_SORT_NEWEST_FIRST;
#endif
notmuch_sort_t sort = NOTMUCH_SORT_NEWEST_FIRST;
#endif
+ argc--; argv++; /* skip subcommand argument */
+
for (i = 0; i < argc && argv[i][0] == '-'; i++) {
if (strcmp (argv[i], "--") == 0) {
i++;
for (i = 0; i < argc && argv[i][0] == '-'; i++) {
if (strcmp (argv[i], "--") == 0) {
i++;
if (notmuch == NULL)
return 1;
if (notmuch == NULL)
return 1;
+ argc--; argv++; /* skip subcommand argument */
+
if (argc && strcmp (argv[0], "--") != 0) {
fprintf (stderr, "Warning: the output file argument of dump is deprecated.\n");
output = fopen (argv[0], "w");
if (argc && strcmp (argv[0], "--") != 0) {
fprintf (stderr, "Warning: the output file argument of dump is deprecated.\n");
output = fopen (argv[0], "w");
add_files_state.verbose = 0;
add_files_state.output_is_a_tty = isatty (fileno (stdout));
add_files_state.verbose = 0;
add_files_state.output_is_a_tty = isatty (fileno (stdout));
+ argc--; argv++; /* skip subcommand argument */
+
for (i = 0; i < argc && argv[i][0] == '-'; i++) {
if (STRNCMP_LITERAL (argv[i], "--verbose") == 0) {
add_files_state.verbose = 1;
for (i = 0; i < argc && argv[i][0] == '-'; i++) {
if (STRNCMP_LITERAL (argv[i], "--verbose") == 0) {
add_files_state.verbose = 1;
params.part = -1;
params.cryptoctx = NULL;
params.part = -1;
params.cryptoctx = NULL;
+ argc--; argv++; /* skip subcommand argument */
+
for (i = 0; i < argc && argv[i][0] == '-'; i++) {
if (strcmp (argv[i], "--") == 0) {
i++;
for (i = 0; i < argc && argv[i][0] == '-'; i++) {
if (strcmp (argv[i], "--") == 0) {
i++;
synchronize_flags = notmuch_config_get_maildir_synchronize_flags (config);
synchronize_flags = notmuch_config_get_maildir_synchronize_flags (config);
+ argc--; argv++; /* skip subcommand argument */
+
if (argc) {
input = fopen (argv[0], "r");
if (input == NULL) {
if (argc) {
input = fopen (argv[0], "r");
if (input == NULL) {
int i, ret;
output_t output = OUTPUT_SUMMARY;
int i, ret;
output_t output = OUTPUT_SUMMARY;
+ argc--; argv++; /* skip subcommand argument */
+
for (i = 0; i < argc && argv[i][0] == '-'; i++) {
if (strcmp (argv[i], "--") == 0) {
i++;
for (i = 0; i < argc && argv[i][0] == '-'; i++) {
if (strcmp (argv[i], "--") == 0) {
i++;
params.cryptoctx = NULL;
params.decrypt = 0;
params.cryptoctx = NULL;
params.decrypt = 0;
+ argc--; argv++; /* skip subcommand argument */
+
for (i = 0; i < argc && argv[i][0] == '-'; i++) {
if (strcmp (argv[i], "--") == 0) {
i++;
for (i = 0; i < argc && argv[i][0] == '-'; i++) {
if (strcmp (argv[i], "--") == 0) {
i++;
+ argc--; argv++; /* skip subcommand argument */
+
for (i = 0; i < argc; i++) {
if (strcmp (argv[i], "--") == 0) {
i++;
for (i = 0; i < argc; i++) {
if (strcmp (argv[i], "--") == 0) {
i++;
command_t *command;
unsigned int i;
command_t *command;
unsigned int i;
+ argc--; argv++; /* Ignore "help" */
+
if (argc == 0) {
printf ("The notmuch mail system.\n\n");
usage (stdout);
if (argc == 0) {
printf ("The notmuch mail system.\n\n");
usage (stdout);
command = &commands[i];
if (strcmp (argv[1], command->name) == 0)
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",
}
fprintf (stderr, "Error: Unknown command '%s' (see \"notmuch help\")\n",