Skip to content

Commit aef7d75

Browse files
szedergitster
authored andcommitted
builtin/bundle.c: let parse-options parse subcommands
'git bundle' parses its subcommands with a couple of if-else if 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. Signed-off-by: SZEDER Gábor <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent fa83cc8 commit aef7d75

File tree

1 file changed

+7
-18
lines changed

1 file changed

+7
-18
lines changed

builtin/bundle.c

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -195,30 +195,19 @@ static int cmd_bundle_unbundle(int argc, const char **argv, const char *prefix)
195195

196196
int cmd_bundle(int argc, const char **argv, const char *prefix)
197197
{
198+
parse_opt_subcommand_fn *fn = NULL;
198199
struct option options[] = {
200+
OPT_SUBCOMMAND("create", &fn, cmd_bundle_create),
201+
OPT_SUBCOMMAND("verify", &fn, cmd_bundle_verify),
202+
OPT_SUBCOMMAND("list-heads", &fn, cmd_bundle_list_heads),
203+
OPT_SUBCOMMAND("unbundle", &fn, cmd_bundle_unbundle),
199204
OPT_END()
200205
};
201-
int result;
202206

203207
argc = parse_options(argc, argv, prefix, options, builtin_bundle_usage,
204-
PARSE_OPT_STOP_AT_NON_OPTION);
208+
0);
205209

206210
packet_trace_identity("bundle");
207211

208-
if (argc < 2)
209-
usage_with_options(builtin_bundle_usage, options);
210-
211-
else if (!strcmp(argv[0], "create"))
212-
result = cmd_bundle_create(argc, argv, prefix);
213-
else if (!strcmp(argv[0], "verify"))
214-
result = cmd_bundle_verify(argc, argv, prefix);
215-
else if (!strcmp(argv[0], "list-heads"))
216-
result = cmd_bundle_list_heads(argc, argv, prefix);
217-
else if (!strcmp(argv[0], "unbundle"))
218-
result = cmd_bundle_unbundle(argc, argv, prefix);
219-
else {
220-
error(_("Unknown subcommand: %s"), argv[0]);
221-
usage_with_options(builtin_bundle_usage, options);
222-
}
223-
return result ? 1 : 0;
212+
return !!fn(argc, argv, prefix);
224213
}

0 commit comments

Comments
 (0)