From 7831917901fffcecca748cc9fcde0282bed9db14 Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Mon, 16 Nov 2015 02:13:14 -0800 Subject: [PATCH] help: Re-write help style now each command has --help --- access-main.go | 11 ++ cat-main.go | 24 ++-- config-alias-main.go | 9 +- config-host-main.go | 8 ++ config-main.go | 25 +++- config-version-main.go | 8 ++ cp-main.go | 11 ++ flags.go | 5 - globals.go | 1 - help-main.go | 48 -------- ls-main.go | 21 ++-- main.go | 5 - mb-main.go | 11 ++ mirror-main.go | 6 +- pipe-main.go | 11 ++ rm-main.go | 7 +- session-main.go | 11 ++ share-download-main.go | 9 +- share-list-main.go | 1 + share-main.go | 21 +++- share-upload-main.go | 9 +- update-main.go | 7 +- vendor/github.com/minio/cli/app.go | 35 +----- vendor/github.com/minio/cli/app_test.go | 88 -------------- vendor/github.com/minio/cli/command.go | 14 --- vendor/github.com/minio/cli/flag.go | 15 --- vendor/github.com/minio/cli/flag_test.go | 144 ----------------------- vendor/github.com/minio/cli/help.go | 6 +- vendor/vendor.json | 4 +- version-main.go | 12 ++ 30 files changed, 193 insertions(+), 394 deletions(-) delete mode 100644 help-main.go diff --git a/access-main.go b/access-main.go index 48138e42..5797743e 100644 --- a/access-main.go +++ b/access-main.go @@ -26,11 +26,19 @@ import ( "github.com/minio/minio-xl/pkg/probe" ) +var ( + accessFlagHelp = cli.BoolFlag{ + Name: "help, h", + Usage: "Help of access", + } +) + // Set access permissions. var accessCmd = cli.Command{ Name: "access", Usage: "Set or get access permissions.", Action: mainAccess, + Flags: []cli.Flag{accessFlagHelp}, CustomHelpTemplate: `Name: mc {{.Name}} - {{.Usage}} @@ -41,6 +49,9 @@ USAGE: PERMISSION: Allowed permissions are: [private, readonly, public, authorized]. +FLAGS: + {{range .Flags}}{{.}} + {{end}} EXAMPLES: 1. Set bucket to "private" on Amazon S3 cloud storage. $ mc {{.Name}} set private https://s3.amazonaws.com/burningman2011 diff --git a/cat-main.go b/cat-main.go index e5041cbd..7bfa3f2b 100644 --- a/cat-main.go +++ b/cat-main.go @@ -30,17 +30,28 @@ import ( "github.com/minio/minio-xl/pkg/probe" ) +var ( + catFlagHelp = cli.BoolFlag{ + Name: "help, h", + Usage: "Help of cat", + } +) + // Display contents of a file. var catCmd = cli.Command{ Name: "cat", Usage: "Display contents of a file.", Action: mainCat, + Flags: []cli.Flag{catFlagHelp}, CustomHelpTemplate: `NAME: mc {{.Name}} - {{.Usage}} USAGE: mc {{.Name}} SOURCE [SOURCE...] +FLAGS: + {{range .Flags}}{{.}} + {{end}} EXAMPLES: 1. Stream an object from Amazon S3 cloud storage to mplayer standard input. $ mc {{.Name}} https://s3.amazonaws.com/ferenginar/klingon_opera_aktuh_maylotah.ogg | mplayer - @@ -51,19 +62,16 @@ EXAMPLES: 3. Concantenate multiple files to one. $ mc {{.Name}} part.* > complete.img - 4. Behave like operating system ‘cat’ tool. Useful for aliasing. - $ alias {{.Name}}='mc --mimic {{.Name}}' - $ {{.Name}} /etc/issue.txt `, } // checkCatSyntax performs command-line input validation for cat command. func checkCatSyntax(ctx *cli.Context) { - if !ctx.Args().Present() && !globalMimicFlag { - cli.ShowCommandHelpAndExit(ctx, "cat", 1) // last argument is exit code + args := ctx.Args() + if !args.Present() { + args = []string{"-"} } - - for _, arg := range ctx.Args() { + for _, arg := range args { if strings.HasPrefix(arg, "-") && len(arg) > 1 { fatalIf(probe.NewError(errors.New("")), fmt.Sprintf("Unknown flag ‘%s’ passed.", arg)) } @@ -116,7 +124,7 @@ func mainCat(ctx *cli.Context) { checkCatSyntax(ctx) stdinMode := false - if globalMimicFlag && !ctx.Args().Present() { + if !ctx.Args().Present() { stdinMode = true } diff --git a/config-alias-main.go b/config-alias-main.go index 0c073f80..b93b74b9 100644 --- a/config-alias-main.go +++ b/config-alias-main.go @@ -16,7 +16,6 @@ package main -// listAliases - list alias import ( "encoding/json" "fmt" @@ -29,10 +28,18 @@ import ( "github.com/minio/minio-xl/pkg/quick" ) +var ( + configAliasFlagHelp = cli.BoolFlag{ + Name: "help, h", + Usage: "Help of config alias", + } +) + var configAliasCmd = cli.Command{ Name: "alias", Usage: "List, modify and remove aliases in configuration file.", Action: mainConfigAlias, + Flags: []cli.Flag{configAliasFlagHelp}, CustomHelpTemplate: `NAME: mc config {{.Name}} - {{.Usage}} diff --git a/config-host-main.go b/config-host-main.go index 06cc4e03..4dfbaf90 100644 --- a/config-host-main.go +++ b/config-host-main.go @@ -14,9 +14,17 @@ import ( "github.com/minio/minio-xl/pkg/quick" ) +var ( + configHostFlagHelp = cli.BoolFlag{ + Name: "help, h", + Usage: "Help of config host", + } +) + var configHostCmd = cli.Command{ Name: "host", Usage: "List, modify and remove hosts in configuration file.", + Flags: []cli.Flag{configHostFlagHelp}, Action: mainConfigHost, CustomHelpTemplate: `NAME: mc config {{.Name}} - {{.Usage}} diff --git a/config-main.go b/config-main.go index 047c0b15..974b31fc 100644 --- a/config-main.go +++ b/config-main.go @@ -28,24 +28,36 @@ import "github.com/minio/cli" // so to avoid taking credentials over cli arguments. It is a security precaution // ---- // + +var ( + configFlagHelp = cli.BoolFlag{ + Name: "help, h", + Usage: "Help of config", + } +) + var configCmd = cli.Command{ Name: "config", Usage: "Manage configuration file.", Action: mainConfig, + Flags: []cli.Flag{configFlagHelp}, Subcommands: []cli.Command{ configAliasCmd, configHostCmd, configVersionCmd, }, CustomHelpTemplate: `NAME: - mc {{.Name}} - {{.Usage}} + {{.Name}} - {{.Usage}} USAGE: - mc {{.Name}} COMMAND + {{.Name}} COMMAND -COMMANDS: - {{range .Subcommands}}{{join .Names ", "}}{{ "\t" }}{{.Usage}} +FLAGS: + {{range .Flags}}{{.}} {{end}} +COMMANDS: + {{range .Commands}}{{join .Names ", "}}{{ "\t" }}{{.Usage}} + {{end}} `, } @@ -53,8 +65,9 @@ COMMANDS: func mainConfig(ctx *cli.Context) { if ctx.Args().First() != "" { // command help. cli.ShowCommandHelp(ctx, ctx.Args().First()) - } else { // mc help. - cli.ShowSubcommandHelp(ctx) + } else { + // command with Subcommands is an App. + cli.ShowAppHelp(ctx) } // sub-commands like "upload" and "download" have their own main. diff --git a/config-version-main.go b/config-version-main.go index 3b72b019..ba4dabd1 100644 --- a/config-version-main.go +++ b/config-version-main.go @@ -24,11 +24,19 @@ import ( "github.com/minio/minio-xl/pkg/probe" ) +var ( + configVersionFlagHelp = cli.BoolFlag{ + Name: "help, h", + Usage: "Help of config version", + } +) + // Print config version. var configVersionCmd = cli.Command{ Name: "version", Usage: "Print config version.", Action: mainConfigVersion, + Flags: []cli.Flag{configVersionFlagHelp}, CustomHelpTemplate: `NAME: mc config {{.Name}} - {{.Usage}} diff --git a/cp-main.go b/cp-main.go index 525589f1..7a28ac84 100644 --- a/cp-main.go +++ b/cp-main.go @@ -34,17 +34,28 @@ import ( "github.com/minio/minio-xl/pkg/probe" ) +var ( + cpFlagHelp = cli.BoolFlag{ + Name: "help, h", + Usage: "Help of cp", + } +) + // Copy command. var cpCmd = cli.Command{ Name: "cp", Usage: "Copy one or more objects to a target.", Action: mainCopy, + Flags: []cli.Flag{cpFlagHelp}, CustomHelpTemplate: `NAME: mc {{.Name}} - {{.Usage}} USAGE: mc {{.Name}} SOURCE [SOURCE...] TARGET +FLAGS: + {{range .Flags}}{{.}} + {{end}} EXAMPLES: 1. Copy a list of objects from local file system to Amazon S3 cloud storage. $ mc {{.Name}} Music/*.ogg https://s3.amazonaws.com/jukebox/ diff --git a/flags.go b/flags.go index a0c1105f..28dea1b8 100644 --- a/flags.go +++ b/flags.go @@ -54,11 +54,6 @@ var ( Usage: "Enable debugging output.", } - mimicFlag = cli.BoolFlag{ - Name: "mimic", - Usage: "Behave like operating system tools. Use with shell aliases.", - } - // Add your new flags starting here ) diff --git a/globals.go b/globals.go index 9cf76ff0..b9c7a071 100644 --- a/globals.go +++ b/globals.go @@ -19,7 +19,6 @@ package main var ( globalQuietFlag = false // Quiet flag set via command line - globalMimicFlag = false // Unix flag set via command line globalJSONFlag = false // Json flag set via command line globalDebugFlag = false // Debug flag set via command line ) diff --git a/help-main.go b/help-main.go deleted file mode 100644 index 80a6538a..00000000 --- a/help-main.go +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Minio Client (C) 2014, 2015 Minio, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package main - -import "github.com/minio/cli" - -// Help command. -var helpCmd = cli.Command{ - Name: "help", - Usage: "Show help.", - Action: mainHelp, - CustomHelpTemplate: `NAME: - mc {{.Name}} - {{.Usage}} - -USAGE: - mc {{.Name}} [COMMAND] - -EXAMPLES: - 1. Show mc usage, commands and global flags. - $ mc {{.Name}} - - 2. Show help for a command. - $ mc {{.Name}} share -`, -} - -// main for help command. -func mainHelp(ctx *cli.Context) { - if ctx.Args().First() != "" { // command help. - cli.ShowCommandHelp(ctx, ctx.Args().First()) - } else { // mc help. - cli.ShowAppHelp(ctx) - } -} diff --git a/ls-main.go b/ls-main.go index 032d3c96..4c5a77f2 100644 --- a/ls-main.go +++ b/ls-main.go @@ -31,6 +31,10 @@ var ( Name: "incomplete, I", Usage: "Remove incomplete uploads.", } + lsFlagHelp = cli.BoolFlag{ + Name: "help, h", + Usage: "Help of ls", + } ) // list files and folders. @@ -38,7 +42,7 @@ var lsCmd = cli.Command{ Name: "ls", Usage: "List files and folders.", Action: mainList, - Flags: []cli.Flag{lsFlagIncomplete}, + Flags: []cli.Flag{lsFlagIncomplete, lsFlagHelp}, CustomHelpTemplate: `NAME: mc {{.Name}} - {{.Usage}} @@ -64,11 +68,7 @@ EXAMPLES: 5. List folders with space separated names on Amazon S3 cloud storage. $ mc {{.Name}} 's3/miniocloud/Community Files/' - 6. Behave like operating system ‘ls’ tool. Useful for aliasing. - $ alias ls='mc --mimic ls' - $ {{.Name}} - - 7. List incomplete (previously failed) uploads of objects on Amazon S3. + 6. List incomplete (previously failed) uploads of objects on Amazon S3. $ mc {{.Name}} --incomplete s3/mybucket `, } @@ -77,13 +77,8 @@ EXAMPLES: func checkListSyntax(ctx *cli.Context) { args := ctx.Args() if !ctx.Args().Present() { - if globalMimicFlag { - args = []string{"."} - } else { - cli.ShowCommandHelpAndExit(ctx, "ls", 1) // last argument is exit code - } + args = []string{"."} } - for _, arg := range args { if strings.TrimSpace(arg) == "" { fatalIf(errInvalidArgument().Trace(), "Unable to validate empty argument.") @@ -106,7 +101,7 @@ func mainList(ctx *cli.Context) { isIncomplete := ctx.Bool("incomplete") // mimic operating system tool behavior - if globalMimicFlag && !ctx.Args().Present() { + if !ctx.Args().Present() { args = []string{"."} } diff --git a/main.go b/main.go index 48f110b7..12abeb0d 100644 --- a/main.go +++ b/main.go @@ -105,7 +105,6 @@ func getSystemData() map[string]string { func registerBefore(ctx *cli.Context) error { setMcConfigDir(ctx.GlobalString("config-folder")) globalQuietFlag = ctx.GlobalBool("quiet") - globalMimicFlag = ctx.GlobalBool("mimic") globalDebugFlag = ctx.GlobalBool("debug") globalJSONFlag = ctx.GlobalBool("json") @@ -139,7 +138,6 @@ func findClosestCommands(command string) []string { func registerApp() *cli.App { // Register all the commands (refer flags.go) - registerCmd(helpCmd) // List contents of a bucket. registerCmd(lsCmd) // List contents of a bucket. registerCmd(mbCmd) // Make a bucket. registerCmd(catCmd) // Display contents of a file. @@ -158,15 +156,12 @@ func registerApp() *cli.App { // register all the flags (refer flags.go) registerFlag(configFlag) // Path to configuration folder. registerFlag(quietFlag) // Suppress chatty console output. - registerFlag(mimicFlag) // Behave like operating system tools. Use with shell aliases. registerFlag(jsonFlag) // Enable json formatted output. registerFlag(debugFlag) // Enable debugging output. registerFlag(colorsFlag) // Choose different styles of console coloring. app := cli.NewApp() app.Usage = "Minio Client for cloud storage and filesystems." - // hide --version flag, version is a command - app.HideVersion = true app.Commands = commands app.Flags = flags app.Author = "Minio.io" diff --git a/mb-main.go b/mb-main.go index 5e06f853..340fb405 100644 --- a/mb-main.go +++ b/mb-main.go @@ -26,17 +26,28 @@ import ( "github.com/minio/minio-xl/pkg/probe" ) +var ( + mbFlagHelp = cli.BoolFlag{ + Name: "help, h", + Usage: "Help of mb", + } +) + // make a bucket or folder. var mbCmd = cli.Command{ Name: "mb", Usage: "Make a bucket or folder.", Action: mainMakeBucket, + Flags: []cli.Flag{mbFlagHelp}, CustomHelpTemplate: `NAME: mc {{.Name}} - {{.Usage}} USAGE: mc {{.Name}} TARGET [TARGET ...] +FLAGS: + {{range .Flags}}{{.}} + {{end}} EXAMPLES: 1. Create a bucket on Amazon S3 cloud storage. $ mc {{.Name}} https://s3.amazonaws.com/mynewbucket diff --git a/mirror-main.go b/mirror-main.go index 88122bfa..a747ed10 100644 --- a/mirror-main.go +++ b/mirror-main.go @@ -39,6 +39,10 @@ var ( Name: "force", Usage: "Force overwrite of an existing target(s).", } + mirrorFlagHelp = cli.BoolFlag{ + Name: "help, h", + Usage: "Help of mirror", + } ) // Mirror folders recursively from a single source to many destinations @@ -46,7 +50,7 @@ var mirrorCmd = cli.Command{ Name: "mirror", Usage: "Mirror folders recursively from a single source to many destinations.", Action: mainMirror, - Flags: []cli.Flag{mirrorFlagForce}, + Flags: []cli.Flag{mirrorFlagForce, mirrorFlagHelp}, CustomHelpTemplate: `NAME: mc {{.Name}} - {{.Usage}} diff --git a/pipe-main.go b/pipe-main.go index bbbb2030..3a35ed05 100644 --- a/pipe-main.go +++ b/pipe-main.go @@ -24,17 +24,28 @@ import ( "github.com/minio/minio-xl/pkg/probe" ) +var ( + pipeFlagHelp = cli.BoolFlag{ + Name: "help, h", + Usage: "Help of pipe", + } +) + // Display contents of a file. var pipeCmd = cli.Command{ Name: "pipe", Usage: "Write contents of stdin to one or more targets. Pipe is the opposite of cat command.", Action: mainPipe, + Flags: []cli.Flag{pipeFlagHelp}, CustomHelpTemplate: `NAME: mc {{.Name}} - {{.Usage}} USAGE: mc {{.Name}} TARGET [TARGET...] +FLAGS: + {{range .Flags}}{{.}} + {{end}} EXAMPLES: 1. Write contents of stdin to an object on Amazon S3 cloud storage. $ mc {{.Name}} https://s3.amazonaws.com/personalbuck/meeting-notes.txt diff --git a/rm-main.go b/rm-main.go index a575144c..77753a5b 100644 --- a/rm-main.go +++ b/rm-main.go @@ -39,6 +39,11 @@ var ( Name: "incomplete, I", Usage: "Remove an incomplete upload(s).", } + + rmFlagHelp = cli.BoolFlag{ + Name: "help, h", + Usage: "Help of rm", + } ) // remove a file or folder. @@ -46,7 +51,7 @@ var rmCmd = cli.Command{ Name: "rm", Usage: "Remove file or bucket [WARNING: Use with care].", Action: mainRm, - Flags: []cli.Flag{rmFlagForce, rmFlagIncomplete}, + Flags: []cli.Flag{rmFlagForce, rmFlagIncomplete, rmFlagHelp}, CustomHelpTemplate: `NAME: mc {{.Name}} - {{.Usage}} diff --git a/session-main.go b/session-main.go index 09411fa6..89fabc73 100644 --- a/session-main.go +++ b/session-main.go @@ -28,11 +28,19 @@ import ( "github.com/minio/minio-xl/pkg/probe" ) +var ( + sessionFlagHelp = cli.BoolFlag{ + Name: "help, h", + Usage: "Help of session", + } +) + // Manage sessions for cp and mirror. var sessionCmd = cli.Command{ Name: "session", Usage: "Manage saved sessions of cp and mirror operations.", Action: mainSession, + Flags: []cli.Flag{sessionFlagHelp}, CustomHelpTemplate: `NAME: mc {{.Name}} - {{.Usage}} @@ -44,6 +52,9 @@ USAGE: SESSION-ID: SESSION - Session can either be $SESSION-ID or "all". +FLAGS: + {{range .Flags}}{{.}} + {{end}} EXAMPLES: 1. List sessions. $ mc {{.Name}} list diff --git a/share-download-main.go b/share-download-main.go index 828bd965..c4712059 100644 --- a/share-download-main.go +++ b/share-download-main.go @@ -25,12 +25,19 @@ import ( "github.com/minio/minio-xl/pkg/probe" ) +var ( + shareFlagDownloadHelp = cli.BoolFlag{ + Name: "help, h", + Usage: "Help of share download", + } +) + // Share documents via URL. var shareDownload = cli.Command{ Name: "download", Usage: "Generate URLs for download access.", Action: mainShareDownload, - Flags: []cli.Flag{shareFlagExpire}, + Flags: []cli.Flag{shareFlagExpire, shareFlagDownloadHelp}, CustomHelpTemplate: `NAME: mc share {{.Name}} - {{.Usage}} diff --git a/share-list-main.go b/share-list-main.go index faa7f34f..163e4086 100644 --- a/share-list-main.go +++ b/share-list-main.go @@ -31,6 +31,7 @@ var shareList = cli.Command{ Action: mainShareList, CustomHelpTemplate: `NAME: mc share {{.Name}} COMMAND - {{.Usage}} + COMMAND: upload: list previously shared access to uploads. download: list previously shared access to downloads. diff --git a/share-main.go b/share-main.go index da556a95..7dfb3b60 100644 --- a/share-main.go +++ b/share-main.go @@ -25,25 +25,36 @@ import ( "github.com/minio/minio-xl/pkg/probe" ) +var ( + shareFlagHelp = cli.BoolFlag{ + Name: "help, h", + Usage: "Help of share", + } +) + // Share documents via URL. var shareCmd = cli.Command{ Name: "share", Usage: "Generate URL for sharing.", Action: mainShare, + Flags: []cli.Flag{shareFlagHelp}, Subcommands: []cli.Command{ shareDownload, shareUpload, shareList, }, CustomHelpTemplate: `NAME: - mc {{.Name}} - {{.Usage}} + {{.Name}} - {{.Usage}} USAGE: - mc {{.Name}} [COMMAND] + {{.Name}} [COMMAND] -COMMANDS: - {{range .Subcommands}}{{join .Names ", "}}{{ "\t" }}{{.Usage}} +FLAGS: + {{range .Flags}}{{.}} {{end}} +COMMANDS: + {{range .Commands}}{{join .Names ", "}}{{ "\t" }}{{.Usage}} + {{end}} `, } @@ -68,7 +79,7 @@ func mainShare(ctx *cli.Context) { if ctx.Args().First() != "" { // command help. cli.ShowCommandHelp(ctx, ctx.Args().First()) } else { // mc help. - cli.ShowSubcommandHelp(ctx) + cli.ShowAppHelp(ctx) } // sub-commands like "upload" and "download" have their own main. diff --git a/share-upload-main.go b/share-upload-main.go index 46f662a3..a7d2d899 100644 --- a/share-upload-main.go +++ b/share-upload-main.go @@ -27,12 +27,19 @@ import ( "github.com/minio/minio-xl/pkg/probe" ) +var ( + shareFlagUploadHelp = cli.BoolFlag{ + Name: "help, h", + Usage: "Help of share download", + } +) + // Share documents via URL. var shareUpload = cli.Command{ Name: "upload", Usage: "Generate ‘curl’ command to upload objects without requiring access/secret keys.", Action: mainShareUpload, - Flags: []cli.Flag{shareFlagExpire, shareFlagContentType}, + Flags: []cli.Flag{shareFlagExpire, shareFlagContentType, shareFlagUploadHelp}, CustomHelpTemplate: `NAME: mc share {{.Name}} - {{.Usage}} diff --git a/update-main.go b/update-main.go index adb40073..09ad6562 100644 --- a/update-main.go +++ b/update-main.go @@ -34,6 +34,11 @@ var ( Name: "experimental, E", Usage: "Check experimental update.", } + + updateFlagHelp = cli.BoolFlag{ + Name: "help, h", + Usage: "Help for update.", + } ) // Check for new software updates. @@ -41,7 +46,7 @@ var updateCmd = cli.Command{ Name: "update", Usage: "Check for a new software update.", Action: mainUpdate, - Flags: []cli.Flag{updateFlagExperimental}, + Flags: []cli.Flag{updateFlagExperimental, updateFlagHelp}, CustomHelpTemplate: `Name: mc {{.Name}} - {{.Usage}} diff --git a/vendor/github.com/minio/cli/app.go b/vendor/github.com/minio/cli/app.go index f0df8ef2..0491b8b0 100644 --- a/vendor/github.com/minio/cli/app.go +++ b/vendor/github.com/minio/cli/app.go @@ -31,10 +31,6 @@ type App struct { Flags []Flag // Boolean to enable bash completion commands EnableBashCompletion bool - // Boolean to hide built-in help command - HideHelp bool - // Boolean to hide built-in version flag - HideVersion 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 @@ -85,8 +81,8 @@ func NewApp() *App { Name: os.Args[0], Usage: "A new cli application", Version: "0.0.0", - BashComplete: DefaultAppComplete, Action: helpCommand.Action, + BashComplete: DefaultAppComplete, Compiled: mustCompileTime(), Writer: os.Stdout, } @@ -119,10 +115,6 @@ func (a *App) getNewContext(arguments []string) (*Context, error) { // Run - Entry point to the cli app. Parses the arguments slice and routes to the proper flag/args combination func (a *App) Run(arguments []string) (err error) { - // Comment this out as its not going to be used - // if a.Author != "" || a.Email != "" { - // a.Authors = append(a.Authors, Author{Name: a.Author, Email: a.Email}) - //} if HelpPrinter == nil { defer func() { HelpPrinter = nil @@ -152,23 +144,11 @@ func (a *App) Run(arguments []string) (err error) { } } - // append help to commands - if a.Command(helpCommand.Name) == nil && !a.HideHelp { - a.Commands = append(a.Commands, helpCommand) - if (HelpFlag != BoolFlag{}) { - a.appendFlag(HelpFlag) - } - } - - //append version/help flags + // append version/help flags if a.EnableBashCompletion { a.appendFlag(BashCompletionFlag) } - if !a.HideVersion { - a.appendFlag(VersionFlag) - } - context, err := a.getNewContext(arguments) if err != nil { return err @@ -217,16 +197,6 @@ func (a *App) RunAndExitOnError() { // RunAsSubcommand - Invokes the subcommand given the context, parses ctx.Args() to generate command-specific flags 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{}) { - a.appendFlag(HelpFlag) - } - } - } - // append flags if a.EnableBashCompletion { a.appendFlag(BashCompletionFlag) @@ -300,7 +270,6 @@ func (a *App) RunAsSubcommand(ctx *Context) (err error) { // Run default Action a.Action(context) - return nil } diff --git a/vendor/github.com/minio/cli/app_test.go b/vendor/github.com/minio/cli/app_test.go index 286251cd..91270c03 100644 --- a/vendor/github.com/minio/cli/app_test.go +++ b/vendor/github.com/minio/cli/app_test.go @@ -1,7 +1,6 @@ package cli_test import ( - "flag" "fmt" "os" "testing" @@ -66,38 +65,6 @@ func ExampleAppSubcommand() { // Hello, Jeremy } -func ExampleAppHelp() { - // set args for examples sake - os.Args = []string{"greet", "h", "describeit"} - - app := cli.NewApp() - app.Name = "greet" - app.Flags = []cli.Flag{ - cli.StringFlag{Name: "name", Value: "bob", Usage: "a name to say"}, - } - app.Commands = []cli.Command{ - { - Name: "describeit", - Aliases: []string{"d"}, - Usage: "use it to see a description", - Description: "This is how we describe describeit the function", - Action: func(c *cli.Context) { - fmt.Printf("i like to describe things") - }, - }, - } - app.Run(os.Args) - // Output: - // NAME: - // describeit - use it to see a description - // - // USAGE: - // command describeit [arguments...] - // - // DESCRIPTION: - // This is how we describe describeit the function -} - func TestApp_Run(t *testing.T) { s := "" @@ -477,61 +444,6 @@ func TestApp_AfterFunc(t *testing.T) { } } -func TestAppNoHelpFlag(t *testing.T) { - oldFlag := cli.HelpFlag - defer func() { - cli.HelpFlag = oldFlag - }() - - cli.HelpFlag = cli.BoolFlag{} - - app := cli.NewApp() - err := app.Run([]string{"test", "-h"}) - - if err != flag.ErrHelp { - t.Errorf("expected error about missing help flag, but got: %s (%T)", err, err) - } -} - -func TestAppHelpPrinter(t *testing.T) { - oldPrinter := cli.HelpPrinter - defer func() { - cli.HelpPrinter = oldPrinter - }() - - var wasCalled = false - cli.HelpPrinter = func(template string, data interface{}) { - wasCalled = true - } - - app := cli.NewApp() - app.Run([]string{"-h"}) - - if wasCalled == false { - t.Errorf("Help printer expected to be called, but was not") - } -} - -func TestAppVersionPrinter(t *testing.T) { - oldPrinter := cli.VersionPrinter - defer func() { - cli.VersionPrinter = oldPrinter - }() - - var wasCalled = false - cli.VersionPrinter = func(c *cli.Context) { - wasCalled = true - } - - app := cli.NewApp() - ctx := cli.NewContext(app, nil, nil) - cli.ShowVersion(ctx) - - if wasCalled == false { - t.Errorf("Version printer expected to be called, but was not") - } -} - func TestAppCommandNotFound(t *testing.T) { beforeRun, subcommandRun := false, false app := cli.NewApp() diff --git a/vendor/github.com/minio/cli/command.go b/vendor/github.com/minio/cli/command.go index 9f5e6a57..cfd77e13 100644 --- a/vendor/github.com/minio/cli/command.go +++ b/vendor/github.com/minio/cli/command.go @@ -34,8 +34,6 @@ type Command struct { Flags []Flag // Treat all flags as normal arguments if true SkipFlagParsing bool - // Boolean to hide built-in help command - HideHelp bool // Boolean to hide this command from help or completion Hide bool // CustomHelpTemplate the text template for the command help topic. @@ -50,14 +48,6 @@ func (c Command) Run(ctx *Context) error { return c.startApp(ctx) } - if !c.HideHelp && (HelpFlag != BoolFlag{}) { - // append help to flags - c.Flags = append( - c.Flags, - HelpFlag, - ) - } - if ctx.App.EnableBashCompletion { c.Flags = append(c.Flags, BashCompletionFlag) } @@ -162,14 +152,11 @@ func (c Command) startApp(ctx *Context) error { // set CommandNotFound app.CommandNotFound = ctx.App.CommandNotFound - app.CustomAppHelpTemplate = c.CustomHelpTemplate - app.HideVersion = ctx.App.HideVersion // set the flags and commands app.Commands = c.Subcommands app.Flags = c.Flags - app.HideHelp = c.HideHelp // bash completion app.EnableBashCompletion = ctx.App.EnableBashCompletion @@ -185,6 +172,5 @@ func (c Command) startApp(ctx *Context) error { } else { app.Action = helpSubcommand.Action } - return app.RunAsSubcommand(ctx) } diff --git a/vendor/github.com/minio/cli/flag.go b/vendor/github.com/minio/cli/flag.go index d8cbf589..f1222782 100644 --- a/vendor/github.com/minio/cli/flag.go +++ b/vendor/github.com/minio/cli/flag.go @@ -14,21 +14,6 @@ var BashCompletionFlag = BoolFlag{ Hide: true, } -// VersionFlag - This flag prints the version for the application -var VersionFlag = BoolFlag{ - Name: "version, v", - Usage: "print the version", -} - -// HelpFlay - This flag prints the help for all commands and subcommands -// Set to the zero value (BoolFlag{}) to disable flag -- keeps subcommand -// unless HideHelp is set to true) it is hidden by default -var HelpFlag = BoolFlag{ - Name: "help, h", - Usage: "show help", - Hide: true, -} - // Flag is a common interface related to parsing flags in cli. // For more advanced flag parsing techniques, it is recomended that // this interface be implemented. diff --git a/vendor/github.com/minio/cli/flag_test.go b/vendor/github.com/minio/cli/flag_test.go index cda91c55..4f0fb078 100644 --- a/vendor/github.com/minio/cli/flag_test.go +++ b/vendor/github.com/minio/cli/flag_test.go @@ -10,39 +10,15 @@ import ( "github.com/minio/cli" ) -var boolFlagTests = []struct { - name string - expected string -}{ - {"help", "--help\t"}, - {"h", "-h\t"}, -} - -func TestBoolFlagHelpOutput(t *testing.T) { - - for _, test := range boolFlagTests { - flag := cli.BoolFlag{Name: test.name} - output := flag.String() - - if output != test.expected { - t.Errorf("%s does not match %s", output, test.expected) - } - } -} - var stringFlagTests = []struct { name string value string expected string }{ - {"help", "", "--help \t"}, - {"h", "", "-h \t"}, - {"h", "", "-h \t"}, {"test", "Something", "--test \"Something\"\t"}, } func TestStringFlagHelpOutput(t *testing.T) { - for _, test := range stringFlagTests { flag := cli.StringFlag{Name: test.name, Value: test.value} output := flag.String() @@ -71,21 +47,6 @@ var stringSliceFlagTests = []struct { value *cli.StringSlice expected string }{ - {"help", func() *cli.StringSlice { - s := &cli.StringSlice{} - s.Set("") - return s - }(), "--help [--help option --help option]\t"}, - {"h", func() *cli.StringSlice { - s := &cli.StringSlice{} - s.Set("") - return s - }(), "-h [-h option -h option]\t"}, - {"h", func() *cli.StringSlice { - s := &cli.StringSlice{} - s.Set("") - return s - }(), "-h [-h option -h option]\t"}, {"test", func() *cli.StringSlice { s := &cli.StringSlice{} s.Set("Something") @@ -94,7 +55,6 @@ var stringSliceFlagTests = []struct { } func TestStringSliceFlagHelpOutput(t *testing.T) { - for _, test := range stringSliceFlagTests { flag := cli.StringSliceFlag{Name: test.name, Value: test.value} output := flag.String() @@ -118,80 +78,11 @@ func TestStringSliceFlagWithEnvVarHelpOutput(t *testing.T) { } } -var intFlagTests = []struct { - name string - expected string -}{ - {"help", "--help \"0\"\t"}, - {"h", "-h \"0\"\t"}, -} - -func TestIntFlagHelpOutput(t *testing.T) { - - for _, test := range intFlagTests { - flag := cli.IntFlag{Name: test.name} - output := flag.String() - - if output != test.expected { - t.Errorf("%s does not match %s", output, test.expected) - } - } -} - -func TestIntFlagWithEnvVarHelpOutput(t *testing.T) { - os.Clearenv() - os.Setenv("APP_BAR", "2") - for _, test := range intFlagTests { - flag := cli.IntFlag{Name: test.name, EnvVar: "APP_BAR"} - output := flag.String() - - if !strings.HasSuffix(output, " [$APP_BAR]") { - t.Errorf("%s does not end with [$APP_BAR]", output) - } - } -} - -var durationFlagTests = []struct { - name string - expected string -}{ - {"help", "--help \"0\"\t"}, - {"h", "-h \"0\"\t"}, -} - -func TestDurationFlagHelpOutput(t *testing.T) { - - for _, test := range durationFlagTests { - flag := cli.DurationFlag{Name: test.name} - output := flag.String() - - if output != test.expected { - t.Errorf("%s does not match %s", output, test.expected) - } - } -} - -func TestDurationFlagWithEnvVarHelpOutput(t *testing.T) { - os.Clearenv() - os.Setenv("APP_BAR", "2h3m6s") - for _, test := range durationFlagTests { - flag := cli.DurationFlag{Name: test.name, EnvVar: "APP_BAR"} - output := flag.String() - - if !strings.HasSuffix(output, " [$APP_BAR]") { - t.Errorf("%s does not end with [$APP_BAR]", output) - } - } -} - var intSliceFlagTests = []struct { name string value *cli.IntSlice expected string }{ - {"help", &cli.IntSlice{}, "--help [--help option --help option]\t"}, - {"h", &cli.IntSlice{}, "-h [-h option -h option]\t"}, - {"h", &cli.IntSlice{}, "-h [-h option -h option]\t"}, {"test", func() *cli.IntSlice { i := &cli.IntSlice{} i.Set("9") @@ -200,7 +91,6 @@ var intSliceFlagTests = []struct { } func TestIntSliceFlagHelpOutput(t *testing.T) { - for _, test := range intSliceFlagTests { flag := cli.IntSliceFlag{Name: test.name, Value: test.value} output := flag.String() @@ -224,39 +114,6 @@ func TestIntSliceFlagWithEnvVarHelpOutput(t *testing.T) { } } -var float64FlagTests = []struct { - name string - expected string -}{ - {"help", "--help \"0\"\t"}, - {"h", "-h \"0\"\t"}, -} - -func TestFloat64FlagHelpOutput(t *testing.T) { - - for _, test := range float64FlagTests { - flag := cli.Float64Flag{Name: test.name} - output := flag.String() - - if output != test.expected { - t.Errorf("%s does not match %s", output, test.expected) - } - } -} - -func TestFloat64FlagWithEnvVarHelpOutput(t *testing.T) { - os.Clearenv() - os.Setenv("APP_BAZ", "99.4") - for _, test := range float64FlagTests { - flag := cli.Float64Flag{Name: test.name, EnvVar: "APP_BAZ"} - output := flag.String() - - if !strings.HasSuffix(output, " [$APP_BAZ]") { - t.Errorf("%s does not end with [$APP_BAZ]", output) - } - } -} - var genericFlagTests = []struct { name string value cli.Generic @@ -267,7 +124,6 @@ var genericFlagTests = []struct { } func TestGenericFlagHelpOutput(t *testing.T) { - for _, test := range genericFlagTests { flag := cli.GenericFlag{Name: test.name, Value: test.value, Usage: "test flag"} output := flag.String() diff --git a/vendor/github.com/minio/cli/help.go b/vendor/github.com/minio/cli/help.go index 683553d6..1a376c26 100644 --- a/vendor/github.com/minio/cli/help.go +++ b/vendor/github.com/minio/cli/help.go @@ -160,7 +160,11 @@ func ShowCommandHelp(c *Context, command string) { app.Commands = append(app.Commands, command) } } - HelpPrinter(DefaultSubcommandHelpTemplate, app) + if app.CustomAppHelpTemplate != "" { + HelpPrinter(app.CustomAppHelpTemplate, app) + } else { + HelpPrinter(DefaultSubcommandHelpTemplate, app) + } return } diff --git a/vendor/vendor.json b/vendor/vendor.json index c6cd0c26..4f602e3e 100644 --- a/vendor/vendor.json +++ b/vendor/vendor.json @@ -24,8 +24,8 @@ }, { "path": "github.com/minio/cli", - "revision": "deb83e228f8fd55ca51942e0de0ec09665b3f63c", - "revisionTime": "2015-11-06T16:14:14-08:00" + "revision": "df3a039fccb1829c39db22b5d3b0fd10effbac2d", + "revisionTime": "2015-11-15T19:40:41-08:00" }, { "path": "github.com/minio/minio-go", diff --git a/version-main.go b/version-main.go index 0cff1689..bd15d28a 100644 --- a/version-main.go +++ b/version-main.go @@ -26,16 +26,28 @@ import ( "github.com/minio/minio-xl/pkg/probe" ) +var ( + versionFlagHelp = cli.BoolFlag{ + Name: "help, h", + Usage: "Help for version.", + } +) + // Print version. var versionCmd = cli.Command{ Name: "version", Usage: "Print version.", Action: mainVersion, + Flags: []cli.Flag{versionFlagHelp}, CustomHelpTemplate: `NAME: mc {{.Name}} - {{.Usage}} USAGE: mc {{.Name}} + +FLAGS: + {{range .Flags}}{{.}} + {{end}} `, }