summaryrefslogtreecommitdiff
path: root/help.c
diff options
context:
space:
mode:
authorNguyễn Thái Ngọc Duy <pclouds@gmail.com>2018-05-20 20:40:00 +0200
committerJunio C Hamano <gitster@pobox.com>2018-05-21 13:23:14 +0900
commit3c7777672bf9bc9ac2ddb422633b39af4faa1682 (patch)
tree13710eec966e2da6bde01cde29e5412bcb808289 /help.c
parent6bb2dc0b9472a84c7d17ee93bda28a7c1c97d415 (diff)
downloadgit-3c7777672bf9bc9ac2ddb422633b39af4faa1682.tar.gz
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>
Diffstat (limited to 'help.c')
-rw-r--r--help.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/help.c b/help.c
index d5ce9dfcbb..1117f7d1d1 100644
--- a/help.c
+++ b/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;