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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



SZEDER Gábor <szeder.dev@xxxxxxxxx> 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);




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux