Subject: Re: [PATCH v2 12/20] builtin/gc.c: let parse-options parse 'git maintenance's subcommands

From: Junio C Hamano <[email-masked]>
Date: Fri, 19 Aug 2022 13:59:02 -0700

SZEDER Gábor <[email-masked]> writes:

> 'git maintenanze' parses its subcommands with a couple of if

nanze?

> statements.  parse-options has just learned to parse subcommands, so
> let's use that facility instead, with the benefits of shorter code,
> handling missing or unknown subcommands, and listing subcommands for
> Bash completion.
>
> This change makes 'git maintenance' consistent with other commands in
> that the help text shown for '-h' goes to standard output, not error,
> in the exit code and error message on unknown subcommand, and the
> error message on missing subcommand.  There is a test checking these,
> which is now updated accordingly.
>
> Note that some of the functions implementing each subcommand don't
> accept any parameters, so add the (unused) 'argc', '**argv' and
> '*prefix' parameters to make them match the type expected by
> parse-options, and thus avoid casting function pointers.

OK.  When the recently posted "unused annotation" and merges down
together with this topic, we would want to add UNUSED() annotation
to them so that we can get closer to be able to compile with -Wunused
warning enabled, but we do not have to worry about it yet.

> +	struct option builtin_maintenance_options[] = {
> +		OPT_SUBCOMMAND("run", &fn, maintenance_run),
> +		OPT_SUBCOMMAND("start", &fn, maintenance_start),
> +		OPT_SUBCOMMAND("stop", &fn, maintenance_stop),
> +		OPT_SUBCOMMAND("register", &fn, maintenance_register),
> +		OPT_SUBCOMMAND("unregister", &fn, maintenance_unregister),
> +		OPT_END(),
> +	};
> +
> +	argc = parse_options(argc, argv, prefix, builtin_maintenance_options,
> +			     builtin_maintenance_usage, 0);
> +	return fn(argc, argv, prefix);