Add HideHelp flag in App and Command

This commit is contained in:
Audrius Butkevicius
2014-07-13 14:16:30 +01:00
parent d38a3b82a6
commit 4a645835f0
2 changed files with 16 additions and 9 deletions

10
app.go
View File

@@ -22,6 +22,8 @@ type App struct {
Flags []Flag
// Boolean to enable bash completion commands
EnableBashCompletion bool
// Boolean to hide built-in help command
HideHelp bool
// An action to execute when the bash-completion flag is set
BashComplete func(context *Context)
// An action to execute before any subcommands are run, but after the context is ready
@@ -66,8 +68,9 @@ func NewApp() *App {
// Entry point to the cli app. Parses the arguments slice and routes to the proper flag/args combination
func (a *App) Run(arguments []string) error {
// append help to commands
if a.Command(helpCommand.Name) == nil {
if a.Command(helpCommand.Name) == nil && !a.HideHelp {
a.Commands = append(a.Commands, helpCommand)
a.appendFlag(HelpFlag)
}
//append version/help flags
@@ -75,7 +78,6 @@ func (a *App) Run(arguments []string) error {
a.appendFlag(BashCompletionFlag)
}
a.appendFlag(VersionFlag)
a.appendFlag(HelpFlag)
// parse flags
set := flagSet(a.Name, a.Flags)
@@ -135,8 +137,9 @@ func (a *App) Run(arguments []string) error {
func (a *App) RunAsSubcommand(ctx *Context) error {
// append help to commands
if len(a.Commands) > 0 {
if a.Command(helpCommand.Name) == nil {
if a.Command(helpCommand.Name) == nil && !a.HideHelp {
a.Commands = append(a.Commands, helpCommand)
a.appendFlag(HelpFlag)
}
}
@@ -144,7 +147,6 @@ func (a *App) RunAsSubcommand(ctx *Context) error {
if a.EnableBashCompletion {
a.appendFlag(BashCompletionFlag)
}
a.appendFlag(HelpFlag)
// parse flags
set := flagSet(a.Name, a.Flags)