help: note the option name on option incompatibility

Change the errors added in d35d03cf93e (help: simplify by moving to OPT_CMDMODE(), 2021-09-22) to quote the offending option at the user when invoked as e.g.: git help --guides garbage Now instead of: fatal: this option doesn't take any other arguments We'll emit: fatal: the '--guides' option doesn't take any non-option arguments Let's also rename the function, as it will be extended to do other checks that aren't "no extra argc" in a subsequent commit. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Ævar Arnfjörð Bjarmason committed Feb 21, 2022 at 20:38 UTC d7f817d376134ec09e6804cdb6e3d062e3308eb9
1 file changed +8 -7
builtin/help.c
+8 -7
@@ -574,11 +574,12 @@ static const char *check_git_cmd(const char* cmd)
574 return cmd;
575 }
576
577 -static void no_extra_argc(int argc)
577 +static void opt_mode_usage(int argc, const char *opt_mode)
578 {
579 if (argc)
580 - usage_msg_opt(_("this option doesn't take any other arguments"),
581 - builtin_help_usage, builtin_help_options);
580 + usage_msg_optf(_("the '%s' option doesn't take any non-option arguments"),
581 + builtin_help_usage, builtin_help_options,
582 + opt_mode);
583 }
584
585 int cmd_help(int argc, const char **argv, const char *prefix)
@@ -604,20 +605,20 @@ int cmd_help(int argc, const char **argv, const char *prefix)
605 printf("%s\n", _(git_more_info_string));
606 break;
607 case HELP_ACTION_GUIDES:
607 - no_extra_argc(argc);
608 + opt_mode_usage(argc, "--guides");
609 list_guides_help();
610 printf("%s\n", _(git_more_info_string));
611 return 0;
612 case HELP_ACTION_CONFIG_FOR_COMPLETION:
612 - no_extra_argc(argc);
613 + opt_mode_usage(argc, "--config-for-completion");
614 list_config_help(SHOW_CONFIG_VARS);
615 return 0;
616 case HELP_ACTION_CONFIG_SECTIONS_FOR_COMPLETION:
616 - no_extra_argc(argc);
617 + opt_mode_usage(argc, "--config-sections-for-completion");
618 list_config_help(SHOW_CONFIG_SECTIONS);
619 return 0;
620 case HELP_ACTION_CONFIG:
620 - no_extra_argc(argc);
621 + opt_mode_usage(argc, "--config");
622 setup_pager();
623 list_config_help(SHOW_CONFIG_HUMAN);
624 printf("\n%s\n", _("'git help config' for more information"));