]> git.ipfire.org Git - thirdparty/git.git/blobdiff - help.c
git: support --list-cmds=list-<category>
[thirdparty/git.git] / help.c
diff --git a/help.c b/help.c
index d5ce9dfcbbbc4ff47588ba5a31c585841d7de687..1117f7d1d1f7b4ba439e5f9d1a08cffd5ff6ecad 100644 (file)
--- 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;