diff options
author | SZEDER Gábor <szeder.dev@gmail.com> | 2022-08-19 19:04:04 +0300 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2022-08-19 21:13:15 +0300 |
commit | f83736ce9d3c76cd5a05d1e647cf5cf0a026f0b6 (patch) | |
tree | 2f0ab8b1cb2986e3de436c03898b98f3235462ab | |
parent | 0350954482bca6accd7b4ad072a1bdb83651b376 (diff) |
builtin/hook.c: let parse-options parse subcommands
'git hook' parses its currently only subcommand with an if statement.
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.
Signed-off-by: SZEDER Gábor <szeder.dev@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rw-r--r-- | builtin/hook.c | 12 |
1 files changed, 4 insertions, 8 deletions
diff --git a/builtin/hook.c b/builtin/hook.c index 54e5c6ec93..b6530d189a 100644 --- a/builtin/hook.c +++ b/builtin/hook.c @@ -67,18 +67,14 @@ usage: int cmd_hook(int argc, const char **argv, const char *prefix) { + parse_opt_subcommand_fn *fn = NULL; struct option builtin_hook_options[] = { + OPT_SUBCOMMAND("run", &fn, run), OPT_END(), }; argc = parse_options(argc, argv, NULL, builtin_hook_options, - builtin_hook_usage, PARSE_OPT_STOP_AT_NON_OPTION); - if (!argc) - goto usage; + builtin_hook_usage, 0); - if (!strcmp(argv[0], "run")) - return run(argc, argv, prefix); - -usage: - usage_with_options(builtin_hook_usage, builtin_hook_options); + return fn(argc, argv, prefix); } |