argument parsing refactoring, round 2
Mark Walters
markwalters1009 at gmail.com
Tue Apr 7 00:19:19 PDT 2015
On Mon, 06 Apr 2015, David Bremner <david at tethera.net> wrote:
> Thanks to Mark for pointing out on IRC that the previous version had problems linking the test suite helpers. That's fixed here by adding a couple stubs.
>
> Here's the diff, roughly with the previous version (actually the first
> hunk is with a slightly later version, where I fixed one bug and
> introduced another).
Hi
I like the shared options and the series in general. I have some very
minor nits:
The first is that I think you missed the second command in
notmuch-search.c: i.e., notmuch_address_command so that doesn't respect
these options. (You could either just add it there or to common_options
if you prefer)
The second is utterly trivial: is it worth having the shared options for
help too? At the moment notmuch help --help just says "sorry --help is
not a command".
The other (very minor things) I will send in replies to the individual
patches.
Best wishes
Mark
>
> diff --git a/notmuch-config.c b/notmuch-config.c
> index 568b3dc..f2cd6a8 100644
> --- a/notmuch-config.c
> +++ b/notmuch-config.c
> @@ -885,9 +885,9 @@ notmuch_config_command (notmuch_config_t *config, int argc, char *argv[])
>
> notmuch_process_shared_options (argv[0]);
>
> - /* skip subcommand argument */
> - argc-= opt_index+1;
> - argv+= opt_index+1;
> + /* skip at least subcommand argument */
> + argc-= opt_index;
> + argv+= opt_index;
>
> if (argc < 1) {
> fprintf (stderr, "Error: notmuch config requires at least one argument.\n");
> diff --git a/notmuch-setup.c b/notmuch-setup.c
> index 5fc6e25..6a020dc 100644
> --- a/notmuch-setup.c
> +++ b/notmuch-setup.c
> @@ -155,7 +155,7 @@ notmuch_setup_command (notmuch_config_t *config,
> if (opt_index < 0)
> return EXIT_FAILURE;
>
> - notmuch_process_shared_options (argv[0]);
> + notmuch_process_shared_options ("setup");
>
> if (notmuch_config_is_new (config))
> welcome_message_pre_setup ();
> diff --git a/test/random-corpus.c b/test/random-corpus.c
> index 790193d..6c467bb 100644
> --- a/test/random-corpus.c
> +++ b/test/random-corpus.c
> @@ -114,6 +114,15 @@ random_utf8_string (void *ctx, size_t char_count)
> return buf;
> }
>
> +/* stubs since we cannot link with notmuch.o */
> +const notmuch_opt_desc_t notmuch_shared_options[] = {
> + { 0, 0, 0, 0, 0 }
> +};
> +
> +void
> +notmuch_process_shared_options (unused (const char *dummy))
> +{
> +}
>
> int
> main (int argc, char **argv)
> _______________________________________________
> notmuch mailing list
> notmuch at notmuchmail.org
> http://notmuchmail.org/mailman/listinfo/notmuch
More information about the notmuch
mailing list