[RFC PATCH 1/2] parse-options: add --git-completion-helper-all

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

 



--git-completion-helper excludes hidden options, such as --allow-empty
for git commit. This is typically helpful, but occasionally we want
auto-completion for obscure flags. --git-completion-helper-all returns
all options, even if they are marked as hidden or nocomplete.

Signed-off-by: Ryan Zoeller <rtzoeller@xxxxxxxxxxxxx>
---
 parse-options.c | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)

diff --git a/parse-options.c b/parse-options.c
index c57618d537..cc7239e1c6 100644
--- a/parse-options.c
+++ b/parse-options.c
@@ -535,8 +535,9 @@ static void show_negated_gitcomp(const struct option *opts, int nr_noopts)
 
 		if (!opts->long_name)
 			continue;
-		if (opts->flags & (PARSE_OPT_HIDDEN | PARSE_OPT_NOCOMPLETE))
-			continue;
+		/* Don't check PARSE_OPT_HIDDEN or PARSE_OPT_NOCOMPLETE,
+		 * we expect the caller to handle these appropriately.
+		 */
 		if (opts->flags & PARSE_OPT_NONEG)
 			continue;
 
@@ -572,7 +573,7 @@ static void show_negated_gitcomp(const struct option *opts, int nr_noopts)
 	}
 }
 
-static int show_gitcomp(const struct option *opts)
+static int show_gitcomp(const struct option *opts, int show_all)
 {
 	const struct option *original_opts = opts;
 	int nr_noopts = 0;
@@ -582,7 +583,8 @@ static int show_gitcomp(const struct option *opts)
 
 		if (!opts->long_name)
 			continue;
-		if (opts->flags & (PARSE_OPT_HIDDEN | PARSE_OPT_NOCOMPLETE))
+		if (!show_all &&
+			(opts->flags & (PARSE_OPT_HIDDEN | PARSE_OPT_NOCOMPLETE)))
 			continue;
 
 		switch (opts->type) {
@@ -723,9 +725,13 @@ int parse_options_step(struct parse_opt_ctx_t *ctx,
 		if (internal_help && ctx->total == 1 && !strcmp(arg + 1, "h"))
 			goto show_usage;
 
-		/* lone --git-completion-helper is asked by git-completion.bash */
+		/* lone --git-completion-helper and --git-completion-helper-all
+		 * are asked by git-completion.bash
+		 */
 		if (ctx->total == 1 && !strcmp(arg + 1, "-git-completion-helper"))
-			return show_gitcomp(options);
+			return show_gitcomp(options, 0);
+		if (ctx->total == 1 && !strcmp(arg + 1, "-git-completion-helper-all"))
+			return show_gitcomp(options, 1);
 
 		if (arg[1] != '-') {
 			ctx->opt = arg + 1;
-- 
2.28.0.260.g5fadab5a9c






[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