From 1b81d8cb19d8da6d865b7fca5a095dd5fec8d209 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= Date: Sun, 20 May 2018 20:40:02 +0200 Subject: help: use command-list.txt for the source of guides MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Signed-off-by: Junio C Hamano --- help.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) (limited to 'help.c') diff --git a/help.c b/help.c index c7df1d2338..23924dd300 100644 --- a/help.c +++ b/help.c @@ -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); -- cgit v1.2.3