Update cli and add CustomAppHelpTemplate
This commit is contained in:
Generated
+2
-2
@@ -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",
|
||||
|
||||
+4
@@ -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
|
||||
|
||||
-35
@@ -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 := ""
|
||||
|
||||
|
||||
+6
-2
@@ -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
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user