help -a: improve and make --verbose default
authorNguyễn Thái Ngọc Duy <pclouds@gmail.com>
Sat, 29 Sep 2018 06:08:14 +0000 (08:08 +0200)
committerJunio C Hamano <gitster@pobox.com>
Thu, 4 Oct 2018 04:23:51 +0000 (21:23 -0700)
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>
Documentation/git-help.txt
builtin/help.c
help.c
t/t0012-help.sh
index 83d25d825aa5a9b68f3cff5290d1ebacef35ebde..206e3aef648a7af8d033c60385c4b73b45b08683 100644 (file)
@@ -8,7 +8,7 @@ git-help - Display help information about Git
 SYNOPSIS
 --------
 [verse]
-'git help' [-a|--all [--verbose]] [-g|--guide]
+'git help' [-a|--all [--[no-]verbose]] [-g|--guide]
           [-i|--info|-m|--man|-w|--web] [COMMAND|GUIDE]
 
 DESCRIPTION
@@ -42,8 +42,10 @@ OPTIONS
 --all::
        Prints all the available commands on the standard output. This
        option overrides any given command or guide name.
-       When used with `--verbose` print description for all recognized
-       commands.
+
+--verbose::
+       When used with `--all` print description for all recognized
+       commands. This is the default.
 
 -c::
 --config::
index 8d4f6dd30152e70d1379a956793b1086fba7f5b6..d83dac283996e59b2012ed3e17f0271f93204212 100644 (file)
@@ -38,7 +38,7 @@ static const char *html_path;
 static int show_all = 0;
 static int show_guides = 0;
 static int show_config;
-static int verbose;
+static int verbose = 1;
 static unsigned int colopts;
 static enum help_format help_format = HELP_FORMAT_NONE;
 static int exclude_guides;
diff --git a/help.c b/help.c
index 96f6d221edc30c3bb8241032b837114693b53a53..4745b322993e6a3c32fa4e2ab8adad9f159193c1 100644 (file)
--- a/help.c
+++ b/help.c
@@ -98,7 +98,8 @@ static int cmd_name_cmp(const void *elem1, const void *elem2)
        return strcmp(e1->name, e2->name);
 }
 
-static void print_cmd_by_category(const struct category_description *catdesc)
+static void print_cmd_by_category(const struct category_description *catdesc,
+                                 int *longest_p)
 {
        struct cmdname_help *cmds;
        int longest = 0;
@@ -124,6 +125,8 @@ static void print_cmd_by_category(const struct category_description *catdesc)
                print_command_list(cmds, mask, longest);
        }
        free(cmds);
+       if (longest_p)
+               *longest_p = longest;
 }
 
 void add_cmdname(struct cmdnames *cmds, const char *name, int len)
@@ -307,7 +310,7 @@ void list_commands(unsigned int colopts,
 void list_common_cmds_help(void)
 {
        puts(_("These are common Git commands used in various situations:"));
-       print_cmd_by_category(common_categories);
+       print_cmd_by_category(common_categories, NULL);
 }
 
 void list_all_main_cmds(struct string_list *list)
@@ -405,7 +408,7 @@ void list_common_guides_help(void)
                { CAT_guide, N_("The common Git guides are:") },
                { 0, NULL }
        };
-       print_cmd_by_category(catdesc);
+       print_cmd_by_category(catdesc, NULL);
        putchar('\n');
 }
 
@@ -494,9 +497,48 @@ void list_config_help(int for_human)
        string_list_clear(&keys, 0);
 }
 
+static int get_alias(const char *var, const char *value, void *data)
+{
+       struct string_list *list = data;
+
+       if (skip_prefix(var, "alias.", &var))
+               string_list_append(list, var)->util = xstrdup(value);
+
+       return 0;
+}
+
 void list_all_cmds_help(void)
 {
-       print_cmd_by_category(main_categories);
+       struct string_list others = STRING_LIST_INIT_DUP;
+       struct string_list alias_list = STRING_LIST_INIT_DUP;
+       struct cmdname_help *aliases;
+       int i, longest;
+
+       printf_ln(_("See 'git help <command>' to read about a specific subcommand"));
+       print_cmd_by_category(main_categories, &longest);
+
+       list_all_other_cmds(&others);
+       if (others.nr)
+               printf("\n%s\n", _("External commands"));
+       for (i = 0; i < others.nr; i++)
+               printf("   %s\n", others.items[i].string);
+       string_list_clear(&others, 0);
+
+       git_config(get_alias, &alias_list);
+       string_list_sort(&alias_list);
+       if (alias_list.nr) {
+               printf("\n%s\n", _("Command aliases"));
+               ALLOC_ARRAY(aliases, alias_list.nr + 1);
+               for (i = 0; i < alias_list.nr; i++) {
+                       aliases[i].name = alias_list.items[i].string;
+                       aliases[i].help = alias_list.items[i].util;
+                       aliases[i].category = 1;
+               }
+               aliases[alias_list.nr].name = NULL;
+               print_command_list(aliases, 1, longest);
+               free(aliases);
+       }
+       string_list_clear(&alias_list, 1);
 }
 
 int is_in_cmdlist(struct cmdnames *c, const char *s)
index bc27df7f383d14fb5fea6266591469c32e562c4e..e8ef7300ecb8693367906d4c314797e5750bdf50 100755 (executable)
@@ -29,9 +29,9 @@ test_expect_success "setup" '
 # to verify
 test_expect_success 'basic help commands' '
        git help >/dev/null &&
-       git help -a >/dev/null &&
+       git help -a --no-verbose >/dev/null &&
        git help -g >/dev/null &&
-       git help -av >/dev/null
+       git help -a >/dev/null
 '
 
 test_expect_success "works for commands and guides by default" '