From fc6c6ff03ae6ddd11e4a537e8b7aade73e2b711d Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Tue, 28 Apr 2015 21:21:45 -0700 Subject: [PATCH] Update cli and add CustomAppHelpTemplate --- Godeps/Godeps.json | 4 +-- .../src/github.com/minio-io/cli/app.go | 4 +++ .../src/github.com/minio-io/cli/app_test.go | 35 ------------------- .../src/github.com/minio-io/cli/help.go | 8 +++-- main.go | 22 ++++++++++++ 5 files changed, 34 insertions(+), 39 deletions(-) diff --git a/Godeps/Godeps.json b/Godeps/Godeps.json index 7443e41d..f6ac610a 100644 --- a/Godeps/Godeps.json +++ b/Godeps/Godeps.json @@ -63,8 +63,8 @@ }, { "ImportPath": "github.com/minio-io/cli", - "Comment": "1.2.0-107-ge085bd3", - "Rev": "e085bd36977e5eddf82401db2f16d91fb1d65412" + "Comment": "1.2.0-108-g4ad376c", + "Rev": "4ad376c97a51a452e36aaa4c19e42560e64be836" }, { "ImportPath": "github.com/minio-io/minio/pkg/iodine", diff --git a/Godeps/_workspace/src/github.com/minio-io/cli/app.go b/Godeps/_workspace/src/github.com/minio-io/cli/app.go index 3e4dfa24..57f1a887 100644 --- a/Godeps/_workspace/src/github.com/minio-io/cli/app.go +++ b/Godeps/_workspace/src/github.com/minio-io/cli/app.go @@ -55,6 +55,10 @@ type App struct { Email string // Writer writer to write output to Writer io.Writer + // CustomAppHelpTemplate the text template for app help topic. + // cli.go uses text/template to render templates. You can + // render custom help text by setting this variable. + CustomAppHelpTemplate string } // mustCompileTime - determines the modification time of the current binary diff --git a/Godeps/_workspace/src/github.com/minio-io/cli/app_test.go b/Godeps/_workspace/src/github.com/minio-io/cli/app_test.go index c9ed5b85..a7c9fd70 100644 --- a/Godeps/_workspace/src/github.com/minio-io/cli/app_test.go +++ b/Godeps/_workspace/src/github.com/minio-io/cli/app_test.go @@ -98,41 +98,6 @@ func ExampleAppHelp() { // This is how we describe describeit the function } -func ExampleAppBashComplete() { - // set args for examples sake - os.Args = []string{"greet", "--generate-bash-completion"} - - app := cli.NewApp() - app.Name = "greet" - app.EnableBashCompletion = true - 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") - }, - }, { - Name: "next", - Usage: "next example", - Description: "more stuff to see when generating bash completion", - Action: func(c *cli.Context) { - fmt.Printf("the next example") - }, - }, - } - - app.Run(os.Args) - // Output: - // describeit - // d - // next - // help - // h -} - func TestApp_Run(t *testing.T) { s := "" diff --git a/Godeps/_workspace/src/github.com/minio-io/cli/help.go b/Godeps/_workspace/src/github.com/minio-io/cli/help.go index 10655754..cb36641c 100644 --- a/Godeps/_workspace/src/github.com/minio-io/cli/help.go +++ b/Godeps/_workspace/src/github.com/minio-io/cli/help.go @@ -8,7 +8,7 @@ import ( // The text template for the Default help topic. // cli.go uses text/template to render templates. You can // render custom help text by setting this variable. -var AppHelpTemplate = `NAME: +var DefaultAppHelpTemplate = `NAME: {{.Name}} - {{.Usage}} USAGE: @@ -118,7 +118,11 @@ func ShowAppHelp(c *Context) { app.Commands = append(app.Commands, command) } } - HelpPrinter(AppHelpTemplate, app) + if app.CustomAppHelpTemplate != "" { + HelpPrinter(app.CustomAppHelpTemplate, app) + } else { + HelpPrinter(DefaultAppHelpTemplate, app) + } } // DefaultAppComplete - Prints the list of subcommands as the default app completion method diff --git a/main.go b/main.go index 8e2b3f99..4a4a8548 100644 --- a/main.go +++ b/main.go @@ -129,5 +129,27 @@ func main() { } return nil } + app.CustomAppHelpTemplate = `NAME: + {{.Name}} - {{.Usage}} + +USAGE: + {{.Name}} {{if .Flags}}[global flags] {{end}}command{{if .Flags}} [command flags]{{end}} [arguments...] + +COMMANDS: + {{range .Commands}}{{join .Names ", "}}{{ "\t" }}{{.Usage}} + {{end}}{{if .Flags}} +GLOBAL FLAGS: + {{range .Flags}}{{.}} + {{end}}{{end}} +VERSION: + {{.Version}} + {{if .Compiled}} +BUILD: + {{.Compiled}}{{end}} + {{range $key, $value := .ExtraInfo}} +{{$key}}: + {{$value}} +{{end}} +` app.RunAndExitOnError() }