summaryrefslogtreecommitdiff
path: root/parse-options.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2018-03-14 19:01:06 (GMT)
committerJunio C Hamano <gitster@pobox.com>2018-03-14 19:01:07 (GMT)
commit7fb6aefd2aaffe66e614f7f7b83e5b7ab16d4806 (patch)
treeef9ef31f2e17a35974152e821b02bd2d8ae33ce6 /parse-options.c
parent99321e327b4df8d9d6724cf26bab7429edbdb718 (diff)
parent27b42d045c06b6138555fef2b00d8d72220bc8be (diff)
downloadgit-7fb6aefd2aaffe66e614f7f7b83e5b7ab16d4806.zip
git-7fb6aefd2aaffe66e614f7f7b83e5b7ab16d4806.tar.gz
git-7fb6aefd2aaffe66e614f7f7b83e5b7ab16d4806.tar.bz2
Merge branch 'nd/parseopt-completion'
Teach parse-options API an option to help the completion script, and make use of the mechanism in command line completion. * nd/parseopt-completion: (45 commits) completion: more subcommands in _git_notes() completion: complete --{reuse,reedit}-message= for all notes subcmds completion: simplify _git_notes completion: don't set PARSE_OPT_NOCOMPLETE on --rerere-autoupdate completion: use __gitcomp_builtin in _git_worktree completion: use __gitcomp_builtin in _git_tag completion: use __gitcomp_builtin in _git_status completion: use __gitcomp_builtin in _git_show_branch completion: use __gitcomp_builtin in _git_rm completion: use __gitcomp_builtin in _git_revert completion: use __gitcomp_builtin in _git_reset completion: use __gitcomp_builtin in _git_replace remote: force completing --mirror= instead of --mirror completion: use __gitcomp_builtin in _git_remote completion: use __gitcomp_builtin in _git_push completion: use __gitcomp_builtin in _git_pull completion: use __gitcomp_builtin in _git_notes completion: use __gitcomp_builtin in _git_name_rev completion: use __gitcomp_builtin in _git_mv completion: use __gitcomp_builtin in _git_merge_base ...
Diffstat (limited to 'parse-options.c')
-rw-r--r--parse-options.c46
1 files changed, 46 insertions, 0 deletions
diff --git a/parse-options.c b/parse-options.c
index d02eb8b..125e84f 100644
--- a/parse-options.c
+++ b/parse-options.c
@@ -425,6 +425,48 @@ 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 = "";
+
+ if (!opts->long_name)
+ continue;
+ if (opts->flags & (PARSE_OPT_HIDDEN | PARSE_OPT_NOCOMPLETE))
+ continue;
+
+ switch (opts->type) {
+ case OPTION_GROUP:
+ continue;
+ case OPTION_STRING:
+ case OPTION_FILENAME:
+ case OPTION_INTEGER:
+ case OPTION_MAGNITUDE:
+ case OPTION_CALLBACK:
+ if (opts->flags & PARSE_OPT_NOARG)
+ break;
+ if (opts->flags & PARSE_OPT_OPTARG)
+ break;
+ if (opts->flags & PARSE_OPT_LASTARG_DEFAULT)
+ break;
+ suffix = "=";
+ break;
+ default:
+ break;
+ }
+ if (opts->flags & PARSE_OPT_COMP_ARG)
+ suffix = "=";
+ printf(" --%s%s", opts->long_name, suffix);
+ }
+ fputc('\n', stdout);
+ exit(0);
+}
+
static int usage_with_options_internal(struct parse_opt_ctx_t *,
const char * const *,
const struct option *, int, int);
@@ -455,6 +497,10 @@ 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 */
+ if (ctx->total == 1 && !strcmp(arg + 1, "-git-completion-helper"))
+ return show_gitcomp(ctx, options);
+
if (arg[1] != '-') {
ctx->opt = arg + 1;
switch (parse_short_opt(ctx, options)) {