help: add "-a --verbose" to list all commands with synopsis

This lists all recognized commands [1] by category. The group order follows closely git.txt. [1] We may actually show commands that are not built (e.g. if you set NO_PERL you don't have git-instaweb but it's still listed here). I ignore the problem because on Linux a git package could be split anyway. The "git-core" package may not contain git-instaweb even if it's built because it may end up in a separate package. We can't know anyway. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Nguyễn Thái Ngọc Duy committed May 20, 2018 at 20:40 UTC 63eae83f8f301a1052cdde254b84f5da00e7b9b6
5 files changed +37 -1
Documentation/git-help.txt
+3 -1
@@ -8,7 +8,7 @@ git-help - Display help information about Git
8 SYNOPSIS
9 --------
10 [verse]
11 -'git help' [-a|--all] [-g|--guide]
11 +'git help' [-a|--all [--verbose]] [-g|--guide]
12 [-i|--info|-m|--man|-w|--web] [COMMAND|GUIDE]
13
14 DESCRIPTION
@@ -42,6 +42,8 @@ OPTIONS
42 --all::
43 Prints all the available commands on the standard output. This
44 option overrides any given command or guide name.
45 + When used with `--verbose` print description for all recognized
46 + commands.
47
48 -g::
49 --guides::
builtin/help.c
+7
@@ -36,6 +36,7 @@ static const char *html_path;
36
37 static int show_all = 0;
38 static int show_guides = 0;
39 +static int verbose;
40 static unsigned int colopts;
41 static enum help_format help_format = HELP_FORMAT_NONE;
42 static int exclude_guides;
@@ -48,6 +49,7 @@ static struct option builtin_help_options[] = {
49 HELP_FORMAT_WEB),
50 OPT_SET_INT('i', "info", &help_format, N_("show info page"),
51 HELP_FORMAT_INFO),
52 + OPT__VERBOSE(&verbose, N_("print command description")),
53 OPT_END(),
54 };
55
@@ -463,6 +465,11 @@ int cmd_help(int argc, const char **argv, const char *prefix)
465
466 if (show_all) {
467 git_config(git_help_config, NULL);
468 + if (verbose) {
469 + setup_pager();
470 + list_all_cmds_help();
471 + return 0;
472 + }
473 printf(_("usage: %s%s"), _(git_usage_string), "\n\n");
474 load_command_list("git-", &main_cmds, &other_cmds);
475 list_commands(colopts, &main_cmds, &other_cmds);
help.c
+16
@@ -27,6 +27,17 @@ static struct category_description common_categories[] = {
27 { CAT_remote, N_("collaborate (see also: git help workflows)") },
28 { 0, NULL }
29 };
30 +static struct category_description main_categories[] = {
31 + { CAT_mainporcelain, N_("Main Porcelain Commands") },
32 + { CAT_ancillarymanipulators, N_("Ancillary Commands / Manipulators") },
33 + { CAT_ancillaryinterrogators, N_("Ancillary Commands / Interrogators") },
34 + { CAT_foreignscminterface, N_("Interacting with Others") },
35 + { CAT_plumbingmanipulators, N_("Low-level Commands / Manipulators") },
36 + { CAT_plumbinginterrogators, N_("Low-level Commands / Interrogators") },
37 + { CAT_synchingrepositories, N_("Low-level Commands / Synching Repositories") },
38 + { CAT_purehelpers, N_("Low-level Commands / Internal Helpers") },
39 + { 0, NULL }
40 +};
41
42 static const char *drop_prefix(const char *name)
43 {
@@ -352,6 +363,11 @@ void list_cmds_by_category(struct string_list *list,
363 }
364 }
365
366 +void list_all_cmds_help(void)
367 +{
368 + print_cmd_by_category(main_categories);
369 +}
370 +
371 int is_in_cmdlist(struct cmdnames *c, const char *s)
372 {
373 int i;
help.h
+2
@@ -19,6 +19,8 @@ static inline void mput_char(char c, unsigned int num)
19 }
20
21 extern void list_common_cmds_help(void);
22 +extern void list_all_cmds_help(void);
23 +
24 extern void list_all_main_cmds(struct string_list *list);
25 extern void list_all_other_cmds(struct string_list *list);
26 extern void list_cmds_by_category(struct string_list *list,
t/t0012-help.sh
+9
@@ -25,6 +25,15 @@ test_expect_success "setup" '
25 EOF
26 '
27
28 +# make sure to exercise these code paths, the output is a bit tricky
29 +# to verify
30 +test_expect_success 'basic help commands' '
31 + git help >/dev/null &&
32 + git help -a >/dev/null &&
33 + git help -g >/dev/null &&
34 + git help -av >/dev/null
35 +'
36 +
37 test_expect_success "works for commands and guides by default" '
38 configure_help &&
39 git help status &&