From: John Keeping Date: Tue, 16 Aug 2016 16:33:34 GMT Subject: Re: [PATCH v3] help: make option --help open man pages only for Git commands Message-ID: <20160816163334.xkkuffjwzc6mw663@john.keeping.me.uk> In-Reply-To: <20160816162030.27754-1-ralf.thielow@gmail.com> On Tue, Aug 16, 2016 at 06:20:30PM +0200, Ralf Thielow wrote: > If option --help is passed to a Git command, we try to open > the man page of that command. However, we do it even for commands > we don't know. Make sure it is a Git command by using "help_unknown_cmd" > which is even able to assume a command if the user made a typo. > > This breaks "git --help" while "git help " still works. > > As " --help" will internally be turned into "help ", > introduce the hidden option "--swapped" in order to know which > version has been called. > > Signed-off-by: Ralf Thielow > --- > Thanks, all, for the help! > > Changes since v2: > - don't check for common guides as the list is very incomplete > - only check for git commands when called via --help (introduce > option --swapped for that), as suggested by Junio > - change test case to check for --help being passed to a concept > used as a git command > > builtin/help.c | 30 +++++++++++++++++++++++------- > git.c | 15 ++++++++++++++- > t/t0012-help.sh | 15 +++++++++++++++ > 3 files changed, 52 insertions(+), 8 deletions(-) > create mode 100755 t/t0012-help.sh > > diff --git a/builtin/help.c b/builtin/help.c > index 8848013..76f07c7 100644 > --- a/builtin/help.c > +++ b/builtin/help.c > @@ -37,7 +37,9 @@ 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 swapped = 0; > static struct option builtin_help_options[] = { > + OPT_BOOL('s', "swapped", &swapped, "mark as being called by --help"), OPT_HIDDEN_BOOL maybe? > OPT_BOOL('a', "all", &show_all, N_("print all available commands")), > 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),