diff mbox series

[v2,5/9] help: note the option name on option incompatibility

Message ID patch-v2-5.9-e5c49089106-20220221T193708Z-avarab@gmail.com (mailing list archive)
State Accepted
Commit d7f817d376134ec09e6804cdb6e3d062e3308eb9
Headers show
Series help: tests, parse_options() sanity, fix "help -g" regression | expand

Commit Message

Ævar Arnfjörð Bjarmason Feb. 21, 2022, 7:38 p.m. UTC
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>
---
 builtin/help.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

Comments

Junio C Hamano Feb. 23, 2022, 10:04 p.m. UTC | #1
Ævar Arnfjörð Bjarmason  <avarab@gmail.com> writes:

> 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

Very good.

> 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>
> ---
>  builtin/help.c | 15 ++++++++-------
>  1 file changed, 8 insertions(+), 7 deletions(-)
>
> diff --git a/builtin/help.c b/builtin/help.c
> index d387131dd83..1c1581ef850 100644
> --- a/builtin/help.c
> +++ b/builtin/help.c
> @@ -574,11 +574,12 @@ static const char *check_git_cmd(const char* cmd)
>  	return cmd;
>  }
>  
> -static void no_extra_argc(int argc)
> +static void opt_mode_usage(int argc, const char *opt_mode)
>  {
>  	if (argc)
> -		usage_msg_opt(_("this option doesn't take any other arguments"),
> -			      builtin_help_usage, builtin_help_options);
> +		usage_msg_optf(_("the '%s' option doesn't take any non-option arguments"),
> +			       builtin_help_usage, builtin_help_options,
> +			       opt_mode);
>  }
>  
>  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)
>  		printf("%s\n", _(git_more_info_string));
>  		break;
>  	case HELP_ACTION_GUIDES:
> -		no_extra_argc(argc);
> +		opt_mode_usage(argc, "--guides");
>  		list_guides_help();
>  		printf("%s\n", _(git_more_info_string));
>  		return 0;
>  	case HELP_ACTION_CONFIG_FOR_COMPLETION:
> -		no_extra_argc(argc);
> +		opt_mode_usage(argc, "--config-for-completion");
>  		list_config_help(SHOW_CONFIG_VARS);
>  		return 0;
>  	case HELP_ACTION_CONFIG_SECTIONS_FOR_COMPLETION:
> -		no_extra_argc(argc);
> +		opt_mode_usage(argc, "--config-sections-for-completion");
>  		list_config_help(SHOW_CONFIG_SECTIONS);
>  		return 0;
>  	case HELP_ACTION_CONFIG:
> -		no_extra_argc(argc);
> +		opt_mode_usage(argc, "--config");
>  		setup_pager();
>  		list_config_help(SHOW_CONFIG_HUMAN);
>  		printf("\n%s\n", _("'git help config' for more information"));
diff mbox series

Patch

diff --git a/builtin/help.c b/builtin/help.c
index d387131dd83..1c1581ef850 100644
--- a/builtin/help.c
+++ b/builtin/help.c
@@ -574,11 +574,12 @@  static const char *check_git_cmd(const char* cmd)
 	return cmd;
 }
 
-static void no_extra_argc(int argc)
+static void opt_mode_usage(int argc, const char *opt_mode)
 {
 	if (argc)
-		usage_msg_opt(_("this option doesn't take any other arguments"),
-			      builtin_help_usage, builtin_help_options);
+		usage_msg_optf(_("the '%s' option doesn't take any non-option arguments"),
+			       builtin_help_usage, builtin_help_options,
+			       opt_mode);
 }
 
 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)
 		printf("%s\n", _(git_more_info_string));
 		break;
 	case HELP_ACTION_GUIDES:
-		no_extra_argc(argc);
+		opt_mode_usage(argc, "--guides");
 		list_guides_help();
 		printf("%s\n", _(git_more_info_string));
 		return 0;
 	case HELP_ACTION_CONFIG_FOR_COMPLETION:
-		no_extra_argc(argc);
+		opt_mode_usage(argc, "--config-for-completion");
 		list_config_help(SHOW_CONFIG_VARS);
 		return 0;
 	case HELP_ACTION_CONFIG_SECTIONS_FOR_COMPLETION:
-		no_extra_argc(argc);
+		opt_mode_usage(argc, "--config-sections-for-completion");
 		list_config_help(SHOW_CONFIG_SECTIONS);
 		return 0;
 	case HELP_ACTION_CONFIG:
-		no_extra_argc(argc);
+		opt_mode_usage(argc, "--config");
 		setup_pager();
 		list_config_help(SHOW_CONFIG_HUMAN);
 		printf("\n%s\n", _("'git help config' for more information"));