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>maint
							parent
							
								
									3c7777672b
								
							
						
					
					
						commit
						63eae83f8f
					
				|  | @ -8,7 +8,7 @@ git-help - Display help information about Git | ||||||
| SYNOPSIS | SYNOPSIS | ||||||
| -------- | -------- | ||||||
| [verse] | [verse] | ||||||
| 'git help' [-a|--all] [-g|--guide] | 'git help' [-a|--all [--verbose]] [-g|--guide] | ||||||
| 	   [-i|--info|-m|--man|-w|--web] [COMMAND|GUIDE] | 	   [-i|--info|-m|--man|-w|--web] [COMMAND|GUIDE] | ||||||
|  |  | ||||||
| DESCRIPTION | DESCRIPTION | ||||||
|  | @ -42,6 +42,8 @@ OPTIONS | ||||||
| --all:: | --all:: | ||||||
| 	Prints all the available commands on the standard output. This | 	Prints all the available commands on the standard output. This | ||||||
| 	option overrides any given command or guide name. | 	option overrides any given command or guide name. | ||||||
|  | 	When used with `--verbose` print description for all recognized | ||||||
|  | 	commands. | ||||||
|  |  | ||||||
| -g:: | -g:: | ||||||
| --guides:: | --guides:: | ||||||
|  |  | ||||||
|  | @ -36,6 +36,7 @@ static const char *html_path; | ||||||
|  |  | ||||||
| static int show_all = 0; | static int show_all = 0; | ||||||
| static int show_guides = 0; | static int show_guides = 0; | ||||||
|  | static int verbose; | ||||||
| static unsigned int colopts; | static unsigned int colopts; | ||||||
| static enum help_format help_format = HELP_FORMAT_NONE; | static enum help_format help_format = HELP_FORMAT_NONE; | ||||||
| static int exclude_guides; | static int exclude_guides; | ||||||
|  | @ -48,6 +49,7 @@ static struct option builtin_help_options[] = { | ||||||
| 			HELP_FORMAT_WEB), | 			HELP_FORMAT_WEB), | ||||||
| 	OPT_SET_INT('i', "info", &help_format, N_("show info page"), | 	OPT_SET_INT('i', "info", &help_format, N_("show info page"), | ||||||
| 			HELP_FORMAT_INFO), | 			HELP_FORMAT_INFO), | ||||||
|  | 	OPT__VERBOSE(&verbose, N_("print command description")), | ||||||
| 	OPT_END(), | 	OPT_END(), | ||||||
| }; | }; | ||||||
|  |  | ||||||
|  | @ -463,6 +465,11 @@ int cmd_help(int argc, const char **argv, const char *prefix) | ||||||
|  |  | ||||||
| 	if (show_all) { | 	if (show_all) { | ||||||
| 		git_config(git_help_config, NULL); | 		git_config(git_help_config, NULL); | ||||||
|  | 		if (verbose) { | ||||||
|  | 			setup_pager(); | ||||||
|  | 			list_all_cmds_help(); | ||||||
|  | 			return 0; | ||||||
|  | 		} | ||||||
| 		printf(_("usage: %s%s"), _(git_usage_string), "\n\n"); | 		printf(_("usage: %s%s"), _(git_usage_string), "\n\n"); | ||||||
| 		load_command_list("git-", &main_cmds, &other_cmds); | 		load_command_list("git-", &main_cmds, &other_cmds); | ||||||
| 		list_commands(colopts, &main_cmds, &other_cmds); | 		list_commands(colopts, &main_cmds, &other_cmds); | ||||||
|  |  | ||||||
							
								
								
									
										16
									
								
								help.c
								
								
								
								
							
							
						
						
									
										16
									
								
								help.c
								
								
								
								
							|  | @ -27,6 +27,17 @@ static struct category_description common_categories[] = { | ||||||
| 	{ CAT_remote, N_("collaborate (see also: git help workflows)") }, | 	{ CAT_remote, N_("collaborate (see also: git help workflows)") }, | ||||||
| 	{ 0, NULL } | 	{ 0, NULL } | ||||||
| }; | }; | ||||||
|  | static struct category_description main_categories[] = { | ||||||
|  | 	{ CAT_mainporcelain, N_("Main Porcelain Commands") }, | ||||||
|  | 	{ CAT_ancillarymanipulators, N_("Ancillary Commands / Manipulators") }, | ||||||
|  | 	{ CAT_ancillaryinterrogators, N_("Ancillary Commands / Interrogators") }, | ||||||
|  | 	{ CAT_foreignscminterface, N_("Interacting with Others") }, | ||||||
|  | 	{ CAT_plumbingmanipulators, N_("Low-level Commands / Manipulators") }, | ||||||
|  | 	{ CAT_plumbinginterrogators, N_("Low-level Commands / Interrogators") }, | ||||||
|  | 	{ CAT_synchingrepositories, N_("Low-level Commands / Synching Repositories") }, | ||||||
|  | 	{ CAT_purehelpers, N_("Low-level Commands / Internal Helpers") }, | ||||||
|  | 	{ 0, NULL } | ||||||
|  | }; | ||||||
|  |  | ||||||
| static const char *drop_prefix(const char *name) | static const char *drop_prefix(const char *name) | ||||||
| { | { | ||||||
|  | @ -352,6 +363,11 @@ void list_cmds_by_category(struct string_list *list, | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
|  | void list_all_cmds_help(void) | ||||||
|  | { | ||||||
|  | 	print_cmd_by_category(main_categories); | ||||||
|  | } | ||||||
|  |  | ||||||
| int is_in_cmdlist(struct cmdnames *c, const char *s) | int is_in_cmdlist(struct cmdnames *c, const char *s) | ||||||
| { | { | ||||||
| 	int i; | 	int i; | ||||||
|  |  | ||||||
							
								
								
									
										2
									
								
								help.h
								
								
								
								
							
							
						
						
									
										2
									
								
								help.h
								
								
								
								
							|  | @ -19,6 +19,8 @@ static inline void mput_char(char c, unsigned int num) | ||||||
| } | } | ||||||
|  |  | ||||||
| extern void list_common_cmds_help(void); | extern void list_common_cmds_help(void); | ||||||
|  | extern void list_all_cmds_help(void); | ||||||
|  |  | ||||||
| extern void list_all_main_cmds(struct string_list *list); | extern void list_all_main_cmds(struct string_list *list); | ||||||
| extern void list_all_other_cmds(struct string_list *list); | extern void list_all_other_cmds(struct string_list *list); | ||||||
| extern void list_cmds_by_category(struct string_list *list, | extern void list_cmds_by_category(struct string_list *list, | ||||||
|  |  | ||||||
|  | @ -25,6 +25,15 @@ test_expect_success "setup" ' | ||||||
| 	EOF | 	EOF | ||||||
| ' | ' | ||||||
|  |  | ||||||
|  | # make sure to exercise these code paths, the output is a bit tricky | ||||||
|  | # to verify | ||||||
|  | test_expect_success 'basic help commands' ' | ||||||
|  | 	git help >/dev/null && | ||||||
|  | 	git help -a >/dev/null && | ||||||
|  | 	git help -g >/dev/null && | ||||||
|  | 	git help -av >/dev/null | ||||||
|  | ' | ||||||
|  |  | ||||||
| test_expect_success "works for commands and guides by default" ' | test_expect_success "works for commands and guides by default" ' | ||||||
| 	configure_help && | 	configure_help && | ||||||
| 	git help status && | 	git help status && | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	 Nguyễn Thái Ngọc Duy
						Nguyễn Thái Ngọc Duy