aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2022-09-13 11:38:24 -0700
committerJunio C Hamano <gitster@pobox.com>2022-09-13 11:38:24 -0700
commit76ffa818c792cf3508502f78909c3b7eb3c72dbc (patch)
treea8df035dcafeea7c95ee6405b0bdd536a2393b75
parentMerge branch 'jk/rev-list-verify-objects-fix' (diff)
parentnotes, remote: show unknown subcommands between `' (diff)
downloadgit-76ffa818c792cf3508502f78909c3b7eb3c72dbc.tar.gz
git-76ffa818c792cf3508502f78909c3b7eb3c72dbc.zip
Merge branch 'sg/parse-options-subcommand'
The codepath for the OPT_SUBCOMMAND facility has been cleaned up. * sg/parse-options-subcommand: notes, remote: show unknown subcommands between `' notes: simplify default operation mode arguments check test-parse-options.c: fix style of comparison with zero test-parse-options.c: don't use for loop initial declaration t0040-parse-options: remove leftover debugging
-rw-r--r--builtin/notes.c11
-rw-r--r--builtin/remote.c2
-rw-r--r--t/helper/test-parse-options.c7
-rwxr-xr-xt/t0040-parse-options.sh2
4 files changed, 12 insertions, 10 deletions
diff --git a/builtin/notes.c b/builtin/notes.c
index 42cbae4659..be51f69225 100644
--- a/builtin/notes.c
+++ b/builtin/notes.c
@@ -995,7 +995,7 @@ static int get_ref(int argc, const char **argv, const char *prefix)
int cmd_notes(int argc, const char **argv, const char *prefix)
{
const char *override_notes_ref = NULL;
- parse_opt_subcommand_fn *fn = list;
+ parse_opt_subcommand_fn *fn = NULL;
struct option options[] = {
OPT_STRING(0, "ref", &override_notes_ref, N_("notes-ref"),
N_("use notes from <notes-ref>")),
@@ -1015,9 +1015,12 @@ int cmd_notes(int argc, const char **argv, const char *prefix)
git_config(git_default_config, NULL);
argc = parse_options(argc, argv, prefix, options, git_notes_usage,
PARSE_OPT_SUBCOMMAND_OPTIONAL);
- if (fn == list && argc && strcmp(argv[0], "list")) {
- error(_("unknown subcommand: %s"), argv[0]);
- usage_with_options(git_notes_usage, options);
+ if (!fn) {
+ if (argc) {
+ error(_("unknown subcommand: `%s'"), argv[0]);
+ usage_with_options(git_notes_usage, options);
+ }
+ fn = list;
}
if (override_notes_ref) {
diff --git a/builtin/remote.c b/builtin/remote.c
index 272c7b8d9e..07117e4c9a 100644
--- a/builtin/remote.c
+++ b/builtin/remote.c
@@ -1768,7 +1768,7 @@ int cmd_remote(int argc, const char **argv, const char *prefix)
return !!fn(argc, argv, prefix);
} else {
if (argc) {
- error(_("unknown subcommand: %s"), argv[0]);
+ error(_("unknown subcommand: `%s'"), argv[0]);
usage_with_options(builtin_remote_usage, options);
}
return !!show_all();
diff --git a/t/helper/test-parse-options.c b/t/helper/test-parse-options.c
index aa0ad45851..506835521a 100644
--- a/t/helper/test-parse-options.c
+++ b/t/helper/test-parse-options.c
@@ -195,7 +195,8 @@ int cmd__parse_options(int argc, const char **argv)
static void print_args(int argc, const char **argv)
{
- for (int i = 0; i < argc; i++)
+ int i;
+ for (i = 0; i < argc; i++)
printf("arg %02d: %s\n", i, argv[i]);
}
@@ -254,7 +255,7 @@ int cmd__parse_options_flags(int argc, const char **argv)
argc = parse_options(argc, argv, NULL, test_flag_options, usage,
PARSE_OPT_STOP_AT_NON_OPTION);
- if (argc == 0 || strcmp(argv[0], "cmd")) {
+ if (!argc || strcmp(argv[0], "cmd")) {
error("'cmd' is mandatory");
usage_with_options(usage, test_flag_options);
}
@@ -312,7 +313,7 @@ int cmd__parse_subcommand(int argc, const char **argv)
argc = parse_options(argc, argv, NULL, test_flag_options, usage,
PARSE_OPT_STOP_AT_NON_OPTION);
- if (argc == 0 || strcmp(argv[0], "cmd")) {
+ if (!argc || strcmp(argv[0], "cmd")) {
error("'cmd' is mandatory");
usage_with_options(usage, test_flag_options);
}
diff --git a/t/t0040-parse-options.sh b/t/t0040-parse-options.sh
index b19b8d3486..5cc62306e3 100755
--- a/t/t0040-parse-options.sh
+++ b/t/t0040-parse-options.sh
@@ -500,7 +500,6 @@ test_expect_success 'KEEP_UNKNOWN_OPT works' '
test_expect_success 'NO_INTERNAL_HELP works for -h' '
test_expect_code 129 test-tool parse-options-flags --no-internal-help cmd -h 2>err &&
- cat err &&
grep "^error: unknown switch \`h$SQ" err &&
grep "^usage: " err
'
@@ -509,7 +508,6 @@ for help_opt in help help-all
do
test_expect_success "NO_INTERNAL_HELP works for --$help_opt" "
test_expect_code 129 test-tool parse-options-flags --no-internal-help cmd --$help_opt 2>err &&
- cat err &&
grep '^error: unknown option \`'$help_opt\' err &&
grep '^usage: ' err
"