summaryrefslogtreecommitdiff
path: root/parse-options.c
diff options
context:
space:
mode:
authorNguyễn Thái Ngọc Duy <pclouds@gmail.com>2018-05-27 10:38:26 +0200
committerJunio C Hamano <gitster@pobox.com>2018-05-29 13:28:44 +0900
commit2b1c01d22ef280ef3a6efd70db2b9aa58359ee36 (patch)
tree4bb3faabcbcbb280d9c3417fccce1c0b87625593 /parse-options.c
parente144d126d74f5d2702870ca9423743102eec6fcd (diff)
downloadgit-2b1c01d22ef280ef3a6efd70db2b9aa58359ee36.tar.gz
parse-options: option to let --git-completion-helper show negative form
When 7fb6aefd2a (Merge branch 'nd/parseopt-completion' - 2018-03-14) is merged, the completion for negative form is left out because the series is alread long and it could be done in a follow up series. This is it. --git-completion-helper now provides --no-xxx so that git-completion.bash can drop the extra custom --no-xxx in the script. It adds a lot more --no-xxx than what's current provided by the git-completion.bash script. We'll trim that down later. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'parse-options.c')
-rw-r--r--parse-options.c22
1 files changed, 18 insertions, 4 deletions
diff --git a/parse-options.c b/parse-options.c
index 0f7059a8ab..b86612148f 100644
--- a/parse-options.c
+++ b/parse-options.c
@@ -427,15 +427,12 @@ void parse_options_start(struct parse_opt_ctx_t *ctx,
parse_options_check(options);
}
-/*
- * TODO: we are not completing the --no-XXX form yet because there are
- * many options that do not suppress it properly.
- */
static int show_gitcomp(struct parse_opt_ctx_t *ctx,
const struct option *opts)
{
for (; opts->type != OPTION_END; opts++) {
const char *suffix = "";
+ int has_unset_form = 0;
if (!opts->long_name)
continue;
@@ -450,6 +447,8 @@ static int show_gitcomp(struct parse_opt_ctx_t *ctx,
case OPTION_INTEGER:
case OPTION_MAGNITUDE:
case OPTION_CALLBACK:
+ has_unset_form = 1;
+
if (opts->flags & PARSE_OPT_NOARG)
break;
if (opts->flags & PARSE_OPT_OPTARG)
@@ -458,12 +457,27 @@ static int show_gitcomp(struct parse_opt_ctx_t *ctx,
break;
suffix = "=";
break;
+ case OPTION_BIT:
+ case OPTION_NEGBIT:
+ case OPTION_COUNTUP:
+ case OPTION_SET_INT:
+ has_unset_form = 1;
+ break;
default:
break;
}
if (opts->flags & PARSE_OPT_COMP_ARG)
suffix = "=";
printf(" --%s%s", opts->long_name, suffix);
+
+ if (has_unset_form && !(opts->flags & PARSE_OPT_NONEG)) {
+ const char *name;
+
+ if (skip_prefix(opts->long_name, "no-", &name))
+ printf(" --%s", name);
+ else
+ printf(" --no-%s", opts->long_name);
+ }
}
fputc('\n', stdout);
exit(0);