|
|
|
@ -44,6 +44,24 @@ OPTIONS:
|
|
|
|
|
{{end}}
|
|
|
|
|
`
|
|
|
|
|
|
|
|
|
|
// The text template for the subcommand help topic.
|
|
|
|
|
// cli.go uses text/template to render templates. You can
|
|
|
|
|
// render custom help text by setting this variable.
|
|
|
|
|
var SubcommandHelpTemplate = `NAME:
|
|
|
|
|
{{.Name}} - {{.Usage}}
|
|
|
|
|
|
|
|
|
|
USAGE:
|
|
|
|
|
{{.Name}} [global options] command [command options] [arguments...]
|
|
|
|
|
|
|
|
|
|
COMMANDS:
|
|
|
|
|
{{range .Commands}}{{.Name}}{{with .ShortName}}, {{.}}{{end}}{{ "\t" }}{{.Usage}}
|
|
|
|
|
{{end}}
|
|
|
|
|
|
|
|
|
|
OPTIONS:
|
|
|
|
|
{{range .Flags}}{{.}}
|
|
|
|
|
{{end}}
|
|
|
|
|
`
|
|
|
|
|
|
|
|
|
|
var helpCommand = Command{
|
|
|
|
|
Name: "help",
|
|
|
|
|
ShortName: "h",
|
|
|
|
@ -58,6 +76,20 @@ var helpCommand = Command{
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var helpSubcommand = Command{
|
|
|
|
|
Name: "help",
|
|
|
|
|
ShortName: "h",
|
|
|
|
|
Usage: "Shows a list of commands or help for one command",
|
|
|
|
|
Action: func(c *Context) {
|
|
|
|
|
args := c.Args()
|
|
|
|
|
if args.Present() {
|
|
|
|
|
ShowCommandHelp(c, args.First())
|
|
|
|
|
} else {
|
|
|
|
|
ShowSubcommandHelp(c)
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Prints help for the App
|
|
|
|
|
var HelpPrinter = printHelp
|
|
|
|
|
|
|
|
|
@ -87,6 +119,11 @@ func ShowCommandHelp(c *Context, command string) {
|
|
|
|
|
fmt.Printf("No help topic for '%v'\n", command)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Prints help for the given subcommand
|
|
|
|
|
func ShowSubcommandHelp(c *Context) {
|
|
|
|
|
HelpPrinter(SubcommandHelpTemplate, c.App)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Prints the version number of the App
|
|
|
|
|
func ShowVersion(c *Context) {
|
|
|
|
|
fmt.Printf("%v version %v\n", c.App.Name, c.App.Version)
|
|
|
|
@ -145,6 +182,15 @@ func checkCommandHelp(c *Context, name string) bool {
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func checkSubcommandHelp(c *Context) bool {
|
|
|
|
|
if c.GlobalBool("h") || c.GlobalBool("help") {
|
|
|
|
|
ShowSubcommandHelp(c)
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func checkCompletions(c *Context) bool {
|
|
|
|
|
if c.GlobalBool(BashCompletionFlag.Name) && c.App.EnableBashCompletion {
|
|
|
|
|
ShowCompletions(c)
|
|
|
|
|