From 22d125a4081c1674ce7a89fc9fdceb4a461ddd14 Mon Sep 17 00:00:00 2001 From: Joe Richey Date: Thu, 16 May 2019 22:36:57 -0700 Subject: [PATCH] Add DisableHelpSubCommand option This option stops the creation of a "help" subcommand for when a CLI tool only wants to have "-h" and "--help" to get examples/usage. This can (in certain situations) help reduce abiguity in documentation. Instead of having two ways to get help about a subcommand ("app help foo" and "app foo --help") there can be only one. As this option defaults to false, the default behavior remains the same. --- command.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/command.go b/command.go index b257f91b..1bb79fd5 100644 --- a/command.go +++ b/command.go @@ -130,6 +130,10 @@ type Command struct { // line of a command when printing help or generating docs DisableFlagsInUseLine bool + // DisableHelpSubCommand will disable the addition of the "help" subcommand. + // The "-h" and "--help" flags will still be available. + DisableHelpSubCommand bool + // DisableSuggestions disables the suggestions based on Levenshtein distance // that go along with 'unknown command' messages. DisableSuggestions bool @@ -938,7 +942,7 @@ func (c *Command) InitDefaultVersionFlag() { // It is called automatically by executing the c or by calling help and usage. // If c already has help command or c has no subcommands, it will do nothing. func (c *Command) InitDefaultHelpCmd() { - if !c.HasSubCommands() { + if c.DisableHelpSubCommand || !c.HasSubCommands() { return }