Commit 0089521c authored by Duy Nguyen's avatar Duy Nguyen Committed by Junio C Hamano

git.c: convert --list-* to --list-cmds=*

Even if these are hidden options, let's make them a bit more generic
since we're introducing more listing types shortly. The code is
structured to allow combining multiple listing types together because
we will soon add more types the 'builtins'.

'parseopt' remains separate because it has separate (SPC) to match
git-completion.bash needs and will not combine with others.
Signed-off-by: Duy Nguyen's avatarNguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
parent 60f487ac
......@@ -163,6 +163,12 @@ foo.bar= ...`) sets `foo.bar` to the empty string which `git config
Do not perform optional operations that require locks. This is
equivalent to setting the `GIT_OPTIONAL_LOCKS` to `0`.
--list-cmds=group[,group...]::
List commands by group. This is an internal/experimental
option and may change or be removed in the future. Supported
groups are: builtins, parseopt (builtin commands that use
parse-options).
GIT COMMANDS
------------
......
......@@ -3049,7 +3049,7 @@ __git_complete_common () {
__git_cmds_with_parseopt_helper=
__git_support_parseopt_helper () {
test -n "$__git_cmds_with_parseopt_helper" ||
__git_cmds_with_parseopt_helper="$(__git --list-parseopt-builtins)"
__git_cmds_with_parseopt_helper="$(__git --list-cmds=parseopt)"
case " $__git_cmds_with_parseopt_helper " in
*" $1 "*)
......
......@@ -38,6 +38,30 @@ static int use_pager = -1;
static void list_builtins(unsigned int exclude_option, char sep);
static int match_token(const char *spec, int len, const char *token)
{
int token_len = strlen(token);
return len == token_len && !strncmp(spec, token, token_len);
}
static int list_cmds(const char *spec)
{
while (*spec) {
const char *sep = strchrnul(spec, ',');
int len = sep - spec;
if (match_token(spec, len, "builtins"))
list_builtins(0, '\n');
else
die(_("unsupported command listing type '%s'"), spec);
spec += len;
if (*spec == ',')
spec++;
}
return 0;
}
static void commit_pager_choice(void) {
switch (use_pager) {
case 0:
......@@ -223,12 +247,13 @@ static int handle_options(const char ***argv, int *argc, int *envchanged)
}
(*argv)++;
(*argc)--;
} else if (!strcmp(cmd, "--list-builtins")) {
list_builtins(0, '\n');
exit(0);
} else if (!strcmp(cmd, "--list-parseopt-builtins")) {
list_builtins(NO_PARSEOPT, ' ');
exit(0);
} else if (skip_prefix(cmd, "--list-cmds=", &cmd)) {
if (!strcmp(cmd, "parseopt")) {
list_builtins(NO_PARSEOPT, ' ');
exit(0);
} else {
exit(list_cmds(cmd));
}
} else {
fprintf(stderr, _("unknown option: %s\n"), cmd);
usage(git_usage_string);
......
......@@ -59,7 +59,7 @@ test_expect_success 'git help' '
'
test_expect_success 'generate builtin list' '
git --list-builtins >builtins
git --list-cmds=builtins >builtins
'
while read builtin
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment