Skip to content

Commit 63eae83

Browse files
pcloudsgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 3c77776 commit 63eae83

File tree

5 files changed

+37
-1
lines changed

5 files changed

+37
-1
lines changed

Documentation/git-help.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ git-help - Display help information about Git
88
SYNOPSIS
99
--------
1010
[verse]
11-
'git help' [-a|--all] [-g|--guide]
11+
'git help' [-a|--all [--verbose]] [-g|--guide]
1212
[-i|--info|-m|--man|-w|--web] [COMMAND|GUIDE]
1313

1414
DESCRIPTION
@@ -42,6 +42,8 @@ OPTIONS
4242
--all::
4343
Prints all the available commands on the standard output. This
4444
option overrides any given command or guide name.
45+
When used with `--verbose` print description for all recognized
46+
commands.
4547

4648
-g::
4749
--guides::

builtin/help.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ static const char *html_path;
3636

3737
static int show_all = 0;
3838
static int show_guides = 0;
39+
static int verbose;
3940
static unsigned int colopts;
4041
static enum help_format help_format = HELP_FORMAT_NONE;
4142
static int exclude_guides;
@@ -48,6 +49,7 @@ static struct option builtin_help_options[] = {
4849
HELP_FORMAT_WEB),
4950
OPT_SET_INT('i', "info", &help_format, N_("show info page"),
5051
HELP_FORMAT_INFO),
52+
OPT__VERBOSE(&verbose, N_("print command description")),
5153
OPT_END(),
5254
};
5355

@@ -463,6 +465,11 @@ int cmd_help(int argc, const char **argv, const char *prefix)
463465

464466
if (show_all) {
465467
git_config(git_help_config, NULL);
468+
if (verbose) {
469+
setup_pager();
470+
list_all_cmds_help();
471+
return 0;
472+
}
466473
printf(_("usage: %s%s"), _(git_usage_string), "\n\n");
467474
load_command_list("git-", &main_cmds, &other_cmds);
468475
list_commands(colopts, &main_cmds, &other_cmds);

help.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,17 @@ static struct category_description common_categories[] = {
2727
{ CAT_remote, N_("collaborate (see also: git help workflows)") },
2828
{ 0, NULL }
2929
};
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+
};
3041

3142
static const char *drop_prefix(const char *name)
3243
{
@@ -352,6 +363,11 @@ void list_cmds_by_category(struct string_list *list,
352363
}
353364
}
354365

366+
void list_all_cmds_help(void)
367+
{
368+
print_cmd_by_category(main_categories);
369+
}
370+
355371
int is_in_cmdlist(struct cmdnames *c, const char *s)
356372
{
357373
int i;

help.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ static inline void mput_char(char c, unsigned int num)
1919
}
2020

2121
extern void list_common_cmds_help(void);
22+
extern void list_all_cmds_help(void);
23+
2224
extern void list_all_main_cmds(struct string_list *list);
2325
extern void list_all_other_cmds(struct string_list *list);
2426
extern void list_cmds_by_category(struct string_list *list,

t/t0012-help.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,15 @@ test_expect_success "setup" '
2525
EOF
2626
'
2727

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+
2837
test_expect_success "works for commands and guides by default" '
2938
configure_help &&
3039
git help status &&

0 commit comments

Comments
 (0)