help: use command-list.txt for the source of guides

The help command currently hard codes the list of guides and their
summary in C. Let's move this list to command-list.txt. This lets us
extract summary lines from Documentation/git*.txt. This also
potentially lets us list guides in git.txt, but I'll leave that for
now.

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:
Nguyễn Thái Ngọc Duy
2018-05-20 20:40:02 +02:00
committed by Junio C Hamano
parent 63eae83f8f
commit 1b81d8cb19
10 changed files with 54 additions and 45 deletions

21
help.c
View File

@ -39,12 +39,14 @@ static struct category_description main_categories[] = {
{ 0, NULL }
};
static const char *drop_prefix(const char *name)
static const char *drop_prefix(const char *name, uint32_t category)
{
const char *new_name;
if (skip_prefix(name, "git-", &new_name))
return new_name;
if (category == CAT_guide && skip_prefix(name, "git", &new_name))
return new_name;
return name;
}
@ -66,7 +68,7 @@ static void extract_cmds(struct cmdname_help **p_cmds, uint32_t mask)
continue;
cmds[nr] = *cmd;
cmds[nr].name = drop_prefix(cmd->name);
cmds[nr].name = drop_prefix(cmd->name, cmd->category);
nr++;
}
@ -358,11 +360,22 @@ void list_cmds_by_category(struct string_list *list,
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));
if (!(cmd->category & cat_id))
continue;
string_list_append(list, drop_prefix(cmd->name, cmd->category));
}
}
void list_common_guides_help(void)
{
struct category_description catdesc[] = {
{ CAT_guide, N_("The common Git guides are:") },
{ 0, NULL }
};
print_cmd_by_category(catdesc);
putchar('\n');
}
void list_all_cmds_help(void)
{
print_cmd_by_category(main_categories);