git: support --list-cmds=list-<category>
This allows us to select any group of commands by a category defined in command-list.txt. This is an internal/hidden option so we don't have to be picky about the category name or worried about exposing too much. This will be used later by git-completion.bash to retrieve certain command groups. 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
6bb2dc0b94
commit
3c7777672b
@ -168,7 +168,8 @@ foo.bar= ...`) sets `foo.bar` to the empty string which `git config
|
||||
option and may change or be removed in the future. Supported
|
||||
groups are: builtins, parseopt (builtin commands that use
|
||||
parse-options), main (all commands in libexec directory),
|
||||
others (all other commands in `$PATH` that have git- prefix).
|
||||
others (all other commands in `$PATH` that have git- prefix),
|
||||
list-<category> (see categories in command-list.txt)
|
||||
|
||||
GIT COMMANDS
|
||||
------------
|
||||
|
@ -45,6 +45,21 @@ define_categories () {
|
||||
test "$bit" -gt 32 && die "Urgh.. too many categories?"
|
||||
}
|
||||
|
||||
define_category_names () {
|
||||
echo
|
||||
echo "/* Category names */"
|
||||
echo "static const char *category_names[] = {"
|
||||
bit=0
|
||||
category_list "$1" |
|
||||
while read cat
|
||||
do
|
||||
echo " \"$cat\", /* (1UL << $bit) */"
|
||||
bit=$(($bit+1))
|
||||
done
|
||||
echo " NULL"
|
||||
echo "};"
|
||||
}
|
||||
|
||||
print_command_list () {
|
||||
echo "static struct cmdname_help command_list[] = {"
|
||||
|
||||
@ -70,4 +85,6 @@ struct cmdname_help {
|
||||
"
|
||||
define_categories "$1"
|
||||
echo
|
||||
define_category_names "$1"
|
||||
echo
|
||||
print_command_list "$1"
|
||||
|
7
git.c
7
git.c
@ -60,6 +60,13 @@ static int list_cmds(const char *spec)
|
||||
list_all_main_cmds(&list);
|
||||
else if (match_token(spec, len, "others"))
|
||||
list_all_other_cmds(&list);
|
||||
else if (len > 5 && !strncmp(spec, "list-", 5)) {
|
||||
struct strbuf sb = STRBUF_INIT;
|
||||
|
||||
strbuf_add(&sb, spec + 5, len - 5);
|
||||
list_cmds_by_category(&list, sb.buf);
|
||||
strbuf_release(&sb);
|
||||
}
|
||||
else
|
||||
die(_("unsupported command listing type '%s'"), spec);
|
||||
spec += len;
|
||||
|
23
help.c
23
help.c
@ -329,6 +329,29 @@ void list_all_other_cmds(struct string_list *list)
|
||||
clean_cmdnames(&other_cmds);
|
||||
}
|
||||
|
||||
void list_cmds_by_category(struct string_list *list,
|
||||
const char *cat)
|
||||
{
|
||||
int i, n = ARRAY_SIZE(command_list);
|
||||
uint32_t cat_id = 0;
|
||||
|
||||
for (i = 0; category_names[i]; i++) {
|
||||
if (!strcmp(cat, category_names[i])) {
|
||||
cat_id = 1UL << i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!cat_id)
|
||||
die(_("unsupported command listing type '%s'"), cat);
|
||||
|
||||
for (i = 0; i < n; i++) {
|
||||
struct cmdname_help *cmd = command_list + i;
|
||||
|
||||
if (cmd->category & cat_id)
|
||||
string_list_append(list, drop_prefix(cmd->name));
|
||||
}
|
||||
}
|
||||
|
||||
int is_in_cmdlist(struct cmdnames *c, const char *s)
|
||||
{
|
||||
int i;
|
||||
|
2
help.h
2
help.h
@ -21,6 +21,8 @@ static inline void mput_char(char c, unsigned int num)
|
||||
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 void list_cmds_by_category(struct string_list *list,
|
||||
const char *category);
|
||||
extern const char *help_unknown_cmd(const char *cmd);
|
||||
extern void load_command_list(const char *prefix,
|
||||
struct cmdnames *main_cmds,
|
||||
|
Loading…
Reference in New Issue
Block a user