help: introduce option --exclude-guides
Introduce option --exclude-guides to the help command. With this option being passed, "git help" will open man pages only for actual commands. Since we know it is a command, we can use function help_unknown_command to give the user advice on typos. Helped-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Ralf Thielow <ralf.thielow@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
3b1c6a9b6e
commit
af74128f4a
@ -37,8 +37,10 @@ static int show_all = 0;
|
||||
static int show_guides = 0;
|
||||
static unsigned int colopts;
|
||||
static enum help_format help_format = HELP_FORMAT_NONE;
|
||||
static int exclude_guides;
|
||||
static struct option builtin_help_options[] = {
|
||||
OPT_BOOL('a', "all", &show_all, N_("print all available commands")),
|
||||
OPT_HIDDEN_BOOL(0, "exclude-guides", &exclude_guides, N_("exclude guides")),
|
||||
OPT_BOOL('g', "guides", &show_guides, N_("print list of useful guides")),
|
||||
OPT_SET_INT('m', "man", &help_format, N_("show man page"), HELP_FORMAT_MAN),
|
||||
OPT_SET_INT('w', "web", &help_format, N_("show manual in web browser"),
|
||||
@ -426,10 +428,29 @@ static void list_common_guides_help(void)
|
||||
putchar('\n');
|
||||
}
|
||||
|
||||
static const char *check_git_cmd(const char* cmd)
|
||||
{
|
||||
char *alias;
|
||||
|
||||
if (is_git_command(cmd))
|
||||
return cmd;
|
||||
|
||||
alias = alias_lookup(cmd);
|
||||
if (alias) {
|
||||
printf_ln(_("`git %s' is aliased to `%s'"), cmd, alias);
|
||||
free(alias);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
if (exclude_guides)
|
||||
return help_unknown_cmd(cmd);
|
||||
|
||||
return cmd;
|
||||
}
|
||||
|
||||
int cmd_help(int argc, const char **argv, const char *prefix)
|
||||
{
|
||||
int nongit;
|
||||
char *alias;
|
||||
enum help_format parsed_help_format;
|
||||
|
||||
argc = parse_options(argc, argv, prefix, builtin_help_options,
|
||||
@ -469,12 +490,7 @@ int cmd_help(int argc, const char **argv, const char *prefix)
|
||||
if (help_format == HELP_FORMAT_NONE)
|
||||
help_format = parse_help_format(DEFAULT_HELP_FORMAT);
|
||||
|
||||
alias = alias_lookup(argv[0]);
|
||||
if (alias && !is_git_command(argv[0])) {
|
||||
printf_ln(_("`git %s' is aliased to `%s'"), argv[0], alias);
|
||||
free(alias);
|
||||
return 0;
|
||||
}
|
||||
argv[0] = check_git_cmd(argv[0]);
|
||||
|
||||
switch (help_format) {
|
||||
case HELP_FORMAT_NONE:
|
||||
|
Reference in New Issue
Block a user