From 9eb8e375c50283b875fa635034c93499b7325ac6 Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Sun, 19 Feb 2017 20:46:06 -0800 Subject: [PATCH] cli: Make sure to add --help flag for subcommands. (#3773) --help is now back and prints properly with command help template. --- cmd/main.go | 6 ++++++ cmd/server-main.go | 1 - cmd/update-main.go | 8 +++++--- cmd/version-main.go | 13 +++++++++---- vendor/github.com/minio/cli/app.go | 20 +++++++++++++------- vendor/github.com/minio/cli/command.go | 15 +++++++++++++-- vendor/vendor.json | 6 +++--- 7 files changed, 49 insertions(+), 20 deletions(-) diff --git a/cmd/main.go b/cmd/main.go index cf091f677..1516cd086 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -104,6 +104,10 @@ func registerApp() *cli.App { registerCommand(updateCmd) // Set up app. + cli.HelpFlag = cli.BoolFlag{ + Name: "help, h", + Usage: "Show help.", + } app := cli.NewApp() app.Name = "Minio" app.Author = "Minio.io" @@ -111,6 +115,8 @@ func registerApp() *cli.App { app.Usage = "Cloud Storage Server." app.Description = `Minio is an Amazon S3 compatible object storage server. Use it to store photos, videos, VMs, containers, log files, or any blob of data as objects.` app.Flags = globalFlags + app.HideVersion = true // Hide `--version` flag, we already have `minio version`. + app.HideHelpCommand = true // Hide `help, h` command, we already have `minio --help`. app.Commands = commands app.CustomAppHelpTemplate = minioHelpTemplate app.CommandNotFound = func(ctx *cli.Context, command string) { diff --git a/cmd/server-main.go b/cmd/server-main.go index b4e063696..d4b4a7852 100644 --- a/cmd/server-main.go +++ b/cmd/server-main.go @@ -79,7 +79,6 @@ EXAMPLES: $ export MINIO_SECRET_KEY=miniostorage $ {{.HelpName}} http://192.168.1.11/mnt/export/ http://192.168.1.12/mnt/export/ \ http://192.168.1.13/mnt/export/ http://192.168.1.14/mnt/export/ - `, } diff --git a/cmd/update-main.go b/cmd/update-main.go index 23721fb2b..ef8716d75 100644 --- a/cmd/update-main.go +++ b/cmd/update-main.go @@ -46,7 +46,7 @@ var updateCmd = cli.Command{ {{.HelpName}} - {{.Usage}} USAGE: - {{.HelpName}} {{if .VisibleFlags}}[FLAGS]{{end}} + {{.HelpName}}{{if .VisibleFlags}} [FLAGS]{{end}} {{if .VisibleFlags}} FLAGS: {{range .VisibleFlags}}{{.}} @@ -56,8 +56,10 @@ EXIT STATUS: 1 - New update is available. -1 - Error in getting update information. -VERSION: - ` + Version + `{{"\n"}}`, +EXAMPLES: + 1. Check if there is a new update available: + $ {{.HelpName}} +`, } const releaseTagTimeLayout = "2006-01-02T15-04-05Z" diff --git a/cmd/version-main.go b/cmd/version-main.go index f3d547c4f..9e1b1ea71 100644 --- a/cmd/version-main.go +++ b/cmd/version-main.go @@ -29,10 +29,15 @@ var versionCmd = cli.Command{ {{.HelpName}} - {{.Usage}} USAGE: - {{.HelpName}} - -VERSION: - ` + Version + `{{"\n"}}`, + {{.HelpName}}{{if .VisibleFlags}} [FLAGS]{{end}} +{{if .VisibleFlags}} +FLAGS: + {{range .VisibleFlags}}{{.}} + {{end}}{{end}} +EXAMPLES: + 1. Prints server version: + $ {{.HelpName}} +`, } func mainVersion(ctx *cli.Context) { diff --git a/vendor/github.com/minio/cli/app.go b/vendor/github.com/minio/cli/app.go index 26a4d4d92..ce5f89f9a 100644 --- a/vendor/github.com/minio/cli/app.go +++ b/vendor/github.com/minio/cli/app.go @@ -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) } } diff --git a/vendor/github.com/minio/cli/command.go b/vendor/github.com/minio/cli/command.go index 1e4ca5cc4..e10e68811 100644 --- a/vendor/github.com/minio/cli/command.go +++ b/vendor/github.com/minio/cli/command.go @@ -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) } diff --git a/vendor/vendor.json b/vendor/vendor.json index a1ed690cf..ff87684b6 100644 --- a/vendor/vendor.json +++ b/vendor/vendor.json @@ -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=",