Skip to content

Commit f83736c

Browse files
szedergitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 0350954 commit f83736c

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

builtin/hook.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,18 +67,14 @@ static int run(int argc, const char **argv, const char *prefix)
6767

6868
int cmd_hook(int argc, const char **argv, const char *prefix)
6969
{
70+
parse_opt_subcommand_fn *fn = NULL;
7071
struct option builtin_hook_options[] = {
72+
OPT_SUBCOMMAND("run", &fn, run),
7173
OPT_END(),
7274
};
7375

7476
argc = parse_options(argc, argv, NULL, builtin_hook_options,
75-
builtin_hook_usage, PARSE_OPT_STOP_AT_NON_OPTION);
76-
if (!argc)
77-
goto usage;
77+
builtin_hook_usage, 0);
7878

79-
if (!strcmp(argv[0], "run"))
80-
return run(argc, argv, prefix);
81-
82-
usage:
83-
usage_with_options(builtin_hook_usage, builtin_hook_options);
79+
return fn(argc, argv, prefix);
8480
}

0 commit comments

Comments
 (0)