help -a: improve and make --verbose default
When you type "git help" (or just "git") you are greeted with a list with commonly used commands and their short description and are suggested to use "git help -a" or "git help -g" for more details. "git help -av" would be more friendly and inline with what is shown with "git help" since it shows list of commands with description as well, and commands are properly grouped. "help -av" does not show everything "help -a" shows though. Add external command section in "help -av" for this. While at there, add a section for aliases as well (until now aliases have no UI, just "git config"). Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Reviewed-by: Taylor Blau <me@ttaylorr.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Nguyễn Thái Ngọc Duy committed
Sep 29, 2018 at 08:08 UTC
26c7d0678324d99b56d3044acfdfab57ee670af4
4 files changed
+54
-10
Documentation/git-help.txt
+5
-3
@@ -8,7 +8,7 @@ git-help - Display help information about Git
8
SYNOPSIS
9
--------
10
[verse]
11
-'git help' [-a|--all [--verbose]] [-g|--guide]
11
+'git help' [-a|--all [--[no-]verbose]] [-g|--guide]
12
[-i|--info|-m|--man|-w|--web] [COMMAND|GUIDE]
13
14
DESCRIPTION
@@ -42,8 +42,10 @@ 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.
45
+
46
+--verbose::
47
+ When used with `--all` print description for all recognized
48
+ commands. This is the default.
49
50
-c::
51
--config::
builtin/help.c
+1
-1
@@ -38,7 +38,7 @@ static const char *html_path;
38
static int show_all = 0;
39
static int show_guides = 0;
40
static int show_config;
41
-static int verbose;
41
+static int verbose = 1;
42
static unsigned int colopts;
43
static enum help_format help_format = HELP_FORMAT_NONE;
44
static int exclude_guides;
help.c
+46
-4
@@ -98,7 +98,8 @@ static int cmd_name_cmp(const void *elem1, const void *elem2)
98
return strcmp(e1->name, e2->name);
99
}
100
101
-static void print_cmd_by_category(const struct category_description *catdesc)
101
+static void print_cmd_by_category(const struct category_description *catdesc,
102
+ int *longest_p)
103
{
104
struct cmdname_help *cmds;
105
int longest = 0;
@@ -124,6 +125,8 @@ static void print_cmd_by_category(const struct category_description *catdesc)
125
print_command_list(cmds, mask, longest);
126
}
127
free(cmds);
128
+ if (longest_p)
129
+ *longest_p = longest;
130
}
131
132
void add_cmdname(struct cmdnames *cmds, const char *name, int len)
@@ -307,7 +310,7 @@ void list_commands(unsigned int colopts,
310
void list_common_cmds_help(void)
311
{
312
puts(_("These are common Git commands used in various situations:"));
310
- print_cmd_by_category(common_categories);
313
+ print_cmd_by_category(common_categories, NULL);
314
}
315
316
void list_all_main_cmds(struct string_list *list)
@@ -405,7 +408,7 @@ void list_common_guides_help(void)
408
{ CAT_guide, N_("The common Git guides are:") },
409
{ 0, NULL }
410
};
408
- print_cmd_by_category(catdesc);
411
+ print_cmd_by_category(catdesc, NULL);
412
putchar('\n');
413
}
414
@@ -494,9 +497,48 @@ void list_config_help(int for_human)
497
string_list_clear(&keys, 0);
498
}
499
500
+static int get_alias(const char *var, const char *value, void *data)
501
+{
502
+ struct string_list *list = data;
503
+
504
+ if (skip_prefix(var, "alias.", &var))
505
+ string_list_append(list, var)->util = xstrdup(value);
506
+
507
+ return 0;
508
+}
509
+
510
void list_all_cmds_help(void)
511
{
499
- print_cmd_by_category(main_categories);
512
+ struct string_list others = STRING_LIST_INIT_DUP;
513
+ struct string_list alias_list = STRING_LIST_INIT_DUP;
514
+ struct cmdname_help *aliases;
515
+ int i, longest;
516
+
517
+ printf_ln(_("See 'git help <command>' to read about a specific subcommand"));
518
+ print_cmd_by_category(main_categories, &longest);
519
+
520
+ list_all_other_cmds(&others);
521
+ if (others.nr)
522
+ printf("\n%s\n", _("External commands"));
523
+ for (i = 0; i < others.nr; i++)
524
+ printf(" %s\n", others.items[i].string);
525
+ string_list_clear(&others, 0);
526
+
527
+ git_config(get_alias, &alias_list);
528
+ string_list_sort(&alias_list);
529
+ if (alias_list.nr) {
530
+ printf("\n%s\n", _("Command aliases"));
531
+ ALLOC_ARRAY(aliases, alias_list.nr + 1);
532
+ for (i = 0; i < alias_list.nr; i++) {
533
+ aliases[i].name = alias_list.items[i].string;
534
+ aliases[i].help = alias_list.items[i].util;
535
+ aliases[i].category = 1;
536
+ }
537
+ aliases[alias_list.nr].name = NULL;
538
+ print_command_list(aliases, 1, longest);
539
+ free(aliases);
540
+ }
541
+ string_list_clear(&alias_list, 1);
542
}
543
544
int is_in_cmdlist(struct cmdnames *c, const char *s)
t/t0012-help.sh
+2
-2
@@ -29,9 +29,9 @@ test_expect_success "setup" '
29
# to verify
30
test_expect_success 'basic help commands' '
31
git help >/dev/null &&
32
- git help -a >/dev/null &&
32
+ git help -a --no-verbose >/dev/null &&
33
git help -g >/dev/null &&
34
- git help -av >/dev/null
34
+ git help -a >/dev/null
35
'
36
37
test_expect_success "works for commands and guides by default" '