Re: [PATCH v2 08/20] parse-options: drop leading space from '--git-completion-helper' output

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, Aug 19 2022, SZEDER Gábor wrote:

> subcommands) a tad more complex, so I wanted to test the result.  The
> test would have to account for the presence of that leading space,
> which bugged my OCD, so let's get rid of it.

On the subject of OCD it...

> Signed-off-by: SZEDER Gábor <szeder.dev@xxxxxxxxx>
> ---
>  parse-options.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/parse-options.c b/parse-options.c
> index a0a2cf98fa..8748f88e6f 100644
> --- a/parse-options.c
> +++ b/parse-options.c
> @@ -620,7 +620,8 @@ static int show_gitcomp(const struct option *opts, int show_all)
>  			suffix = "=";
>  		if (starts_with(opts->long_name, "no-"))
>  			nr_noopts++;
> -		printf(" --%s%s", opts->long_name, suffix);
> +		printf("%s--%s%s", opts == original_opts ? "" : " ",
> +		       opts->long_name, suffix);
>  	}
>  	show_negated_gitcomp(original_opts, show_all, -1);
>  	show_negated_gitcomp(original_opts, show_all, nr_noopts);

...bugs me a bit that we have a "suffix" variable, but not a "prefix"
for this, maybe this? We could also make the prefix a "const char
*const" to indicate that we don't modify it in the "for" body:

diff --git a/parse-options.c b/parse-options.c
index edf55d3ef5d..3000121e5c0 100644
--- a/parse-options.c
+++ b/parse-options.c
@@ -589,6 +589,7 @@ static int show_gitcomp(const struct option *opts, int show_all)
 	int nr_noopts = 0;
 
 	for (; opts->type != OPTION_END; opts++) {
+		const char *prefix = opts == original_opts ? "" : " ";
 		const char *suffix = "";
 
 		if (!opts->long_name)
@@ -620,7 +621,7 @@ static int show_gitcomp(const struct option *opts, int show_all)
 			suffix = "=";
 		if (starts_with(opts->long_name, "no-"))
 			nr_noopts++;
-		printf(" --%s%s", opts->long_name, suffix);
+		printf("%s--%s%s", opts->long_name, prefix, suffix);
 	}
 	show_negated_gitcomp(original_opts, show_all, -1);
 	show_negated_gitcomp(original_opts, show_all, nr_noopts);




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux