mirror of
https://github.com/git/git.git
synced 2024-05-19 09:26:09 +02:00
completion: implement and use --list-cmds=main,others
This is part of the effort to break down and provide commands by category in machine-readable form. This could be helpful later on when completion script switches to use --list-cmds for selecting completable commands. It would be much easier for the user to choose to complete _all_ commands instead of the default selection by passing different values to --list-cmds in git-completino.bash. While at there, replace "git help -a" in git-completion.bash with --list-cmds since it's better suited for this task. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
e5d7a61953
commit
6bb2dc0b94
|
@ -167,7 +167,8 @@ foo.bar= ...`) sets `foo.bar` to the empty string which `git config
|
||||||
List commands by group. This is an internal/experimental
|
List commands by group. This is an internal/experimental
|
||||||
option and may change or be removed in the future. Supported
|
option and may change or be removed in the future. Supported
|
||||||
groups are: builtins, parseopt (builtin commands that use
|
groups are: builtins, parseopt (builtin commands that use
|
||||||
parse-options).
|
parse-options), main (all commands in libexec directory),
|
||||||
|
others (all other commands in `$PATH` that have git- prefix).
|
||||||
|
|
||||||
GIT COMMANDS
|
GIT COMMANDS
|
||||||
------------
|
------------
|
||||||
|
|
|
@ -839,7 +839,7 @@ __git_commands () {
|
||||||
then
|
then
|
||||||
printf "%s" "${GIT_TESTING_COMMAND_COMPLETION}"
|
printf "%s" "${GIT_TESTING_COMMAND_COMPLETION}"
|
||||||
else
|
else
|
||||||
git help -a|egrep '^ [a-zA-Z0-9]'
|
git --list-cmds=main,others
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
4
git.c
4
git.c
|
@ -56,6 +56,10 @@ static int list_cmds(const char *spec)
|
||||||
|
|
||||||
if (match_token(spec, len, "builtins"))
|
if (match_token(spec, len, "builtins"))
|
||||||
list_builtins(&list, 0);
|
list_builtins(&list, 0);
|
||||||
|
else if (match_token(spec, len, "main"))
|
||||||
|
list_all_main_cmds(&list);
|
||||||
|
else if (match_token(spec, len, "others"))
|
||||||
|
list_all_other_cmds(&list);
|
||||||
else
|
else
|
||||||
die(_("unsupported command listing type '%s'"), spec);
|
die(_("unsupported command listing type '%s'"), spec);
|
||||||
spec += len;
|
spec += len;
|
||||||
|
|
32
help.c
32
help.c
|
@ -297,6 +297,38 @@ void list_common_cmds_help(void)
|
||||||
print_cmd_by_category(common_categories);
|
print_cmd_by_category(common_categories);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void list_all_main_cmds(struct string_list *list)
|
||||||
|
{
|
||||||
|
struct cmdnames main_cmds, other_cmds;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
memset(&main_cmds, 0, sizeof(main_cmds));
|
||||||
|
memset(&other_cmds, 0, sizeof(other_cmds));
|
||||||
|
load_command_list("git-", &main_cmds, &other_cmds);
|
||||||
|
|
||||||
|
for (i = 0; i < main_cmds.cnt; i++)
|
||||||
|
string_list_append(list, main_cmds.names[i]->name);
|
||||||
|
|
||||||
|
clean_cmdnames(&main_cmds);
|
||||||
|
clean_cmdnames(&other_cmds);
|
||||||
|
}
|
||||||
|
|
||||||
|
void list_all_other_cmds(struct string_list *list)
|
||||||
|
{
|
||||||
|
struct cmdnames main_cmds, other_cmds;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
memset(&main_cmds, 0, sizeof(main_cmds));
|
||||||
|
memset(&other_cmds, 0, sizeof(other_cmds));
|
||||||
|
load_command_list("git-", &main_cmds, &other_cmds);
|
||||||
|
|
||||||
|
for (i = 0; i < other_cmds.cnt; i++)
|
||||||
|
string_list_append(list, other_cmds.names[i]->name);
|
||||||
|
|
||||||
|
clean_cmdnames(&main_cmds);
|
||||||
|
clean_cmdnames(&other_cmds);
|
||||||
|
}
|
||||||
|
|
||||||
int is_in_cmdlist(struct cmdnames *c, const char *s)
|
int is_in_cmdlist(struct cmdnames *c, const char *s)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
4
help.h
4
help.h
|
@ -1,6 +1,8 @@
|
||||||
#ifndef HELP_H
|
#ifndef HELP_H
|
||||||
#define HELP_H
|
#define HELP_H
|
||||||
|
|
||||||
|
struct string_list;
|
||||||
|
|
||||||
struct cmdnames {
|
struct cmdnames {
|
||||||
int alloc;
|
int alloc;
|
||||||
int cnt;
|
int cnt;
|
||||||
|
@ -17,6 +19,8 @@ static inline void mput_char(char c, unsigned int num)
|
||||||
}
|
}
|
||||||
|
|
||||||
extern void list_common_cmds_help(void);
|
extern void list_common_cmds_help(void);
|
||||||
|
extern void list_all_main_cmds(struct string_list *list);
|
||||||
|
extern void list_all_other_cmds(struct string_list *list);
|
||||||
extern const char *help_unknown_cmd(const char *cmd);
|
extern const char *help_unknown_cmd(const char *cmd);
|
||||||
extern void load_command_list(const char *prefix,
|
extern void load_command_list(const char *prefix,
|
||||||
struct cmdnames *main_cmds,
|
struct cmdnames *main_cmds,
|
||||||
|
|
Loading…
Reference in New Issue