cli: Make sure to add --help flag for subcommands. (#3773)

--help is now back and prints properly with command
help template.
This commit is contained in:
Harshavardhana
2017-02-19 20:46:06 -08:00
committed by GitHub
parent 7ea1de8245
commit 9eb8e375c5
7 changed files with 49 additions and 20 deletions

20
vendor/github.com/minio/cli/app.go generated vendored
View File

@@ -45,8 +45,10 @@ type App struct {
Flags []Flag
// Boolean to enable bash completion commands
EnableBashCompletion bool
// Boolean to hide built-in help command
// Boolean to hide built-in help flag
HideHelp bool
// Boolean to hide built-in help command
HideHelpCommand bool
// Boolean to hide built-in version flag and the VERSION section of help
HideVersion bool
// Populate on app startup, only gettable through method Categories()
@@ -144,9 +146,11 @@ func (a *App) Setup() {
}
a.Commands = newCmds
if a.Command(helpCommand.Name) == nil && !a.HideHelp {
a.Commands = append(a.Commands, helpCommand)
if (HelpFlag != BoolFlag{}) {
if a.Command(helpCommand.Name) == nil {
if !a.HideHelpCommand {
a.Commands = append(a.Commands, helpCommand)
}
if !a.HideHelp && (HelpFlag != BoolFlag{}) {
a.appendFlag(HelpFlag)
}
}
@@ -285,9 +289,11 @@ func (a *App) RunAndExitOnError() {
func (a *App) RunAsSubcommand(ctx *Context) (err error) {
// append help to commands
if len(a.Commands) > 0 {
if a.Command(helpCommand.Name) == nil && !a.HideHelp {
a.Commands = append(a.Commands, helpCommand)
if (HelpFlag != BoolFlag{}) {
if a.Command(helpCommand.Name) == nil {
if !a.HideHelpCommand {
a.Commands = append(a.Commands, helpCommand)
}
if !a.HideHelp && (HelpFlag != BoolFlag{}) {
a.appendFlag(HelpFlag)
}
}

View File

@@ -51,8 +51,10 @@ type Command struct {
// removed n version 2 since it only works under specific conditions so we
// backport here by exposing it as an option for compatibility.
SkipArgReorder bool
// Boolean to hide built-in help command
// Boolean to hide built-in help flag
HideHelp bool
// Boolean to hide built-in help command
HideHelpCommand bool
// Boolean to hide this command from help or completion
Hidden bool
@@ -261,6 +263,7 @@ func (c Command) startApp(ctx *Context) error {
app.Commands = c.Subcommands
app.Flags = c.Flags
app.HideHelp = c.HideHelp
app.HideHelpCommand = c.HideHelpCommand
app.Version = ctx.App.Version
app.HideVersion = ctx.App.HideVersion
@@ -301,5 +304,13 @@ func (c Command) startApp(ctx *Context) error {
// VisibleFlags returns a slice of the Flags with Hidden=false
func (c Command) VisibleFlags() []Flag {
return visibleFlags(c.Flags)
flags := c.Flags
if !c.HideHelp && (HelpFlag != BoolFlag{}) {
// append help to flags
flags = append(
flags,
HelpFlag,
)
}
return visibleFlags(flags)
}

6
vendor/vendor.json vendored
View File

@@ -163,10 +163,10 @@
"revisionTime": "2016-07-23T06:10:19Z"
},
{
"checksumSHA1": "iDDGi0/U33hxoaQBgM3ww882lmU=",
"checksumSHA1": "7PcmjItrQSx/1sZ6Q395LCzT+iw=",
"path": "github.com/minio/cli",
"revision": "cea7bbb0e52ac4d24c1de3f450545f38246075a2",
"revisionTime": "2017-02-15T09:44:04Z"
"revision": "06bb2061ef1493532baf0444818eb5fb4c83caac",
"revisionTime": "2017-02-20T03:57:28Z"
},
{
"checksumSHA1": "NBGyq2+iTtJvJ+ElG4FzHLe1WSY=",