JMS #5: Starting support for subcommand docs
This commit is contained in:
parent
6dbfe20872
commit
0dd327f6e5
38
help.go
38
help.go
@ -12,28 +12,40 @@ var helpCommand = Command{
|
|||||||
ShortName: "h",
|
ShortName: "h",
|
||||||
Usage: "Shows a list of commands or help for one command",
|
Usage: "Shows a list of commands or help for one command",
|
||||||
Action: func(c *Context) {
|
Action: func(c *Context) {
|
||||||
helpTemplate := `NAME:
|
args := c.Args()
|
||||||
{{.Name}} - {{.Usage}}
|
if len(args) > 0 {
|
||||||
|
showCommandHelp(c)
|
||||||
|
} else {
|
||||||
|
showAppHelp(c)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
func showAppHelp(c *Context) {
|
||||||
|
helpTemplate := `NAME:
|
||||||
|
{{.Name}} - {{.Usage}}
|
||||||
|
|
||||||
USAGE:
|
USAGE:
|
||||||
{{.Name}} [global options] command [command options] [arguments...]
|
{{.Name}} [global options] command [command options] [arguments...]
|
||||||
|
|
||||||
VERSION:
|
VERSION:
|
||||||
{{.Version}}
|
{{.Version}}
|
||||||
|
|
||||||
COMMANDS:
|
COMMANDS:
|
||||||
{{range .Commands}}{{.Name}}{{with .ShortName}}, {{.}}{{end}}{{ "\t" }}{{.Usage}}
|
{{range .Commands}}{{.Name}}{{with .ShortName}}, {{.}}{{end}}{{ "\t" }}{{.Usage}}
|
||||||
{{end}}
|
{{end}}
|
||||||
GLOBAL OPTIONS:
|
GLOBAL OPTIONS:
|
||||||
{{range .Flags}}{{.}}
|
{{range .Flags}}{{.}}
|
||||||
{{end}}
|
{{end}}
|
||||||
`
|
`
|
||||||
|
|
||||||
w := tabwriter.NewWriter(os.Stdout, 0, 8, 1, '\t', 0)
|
w := tabwriter.NewWriter(os.Stdout, 0, 8, 1, '\t', 0)
|
||||||
t := template.Must(template.New("help").Parse(helpTemplate))
|
t := template.Must(template.New("help").Parse(helpTemplate))
|
||||||
t.Execute(w, c.App)
|
t.Execute(w, c.App)
|
||||||
w.Flush()
|
w.Flush()
|
||||||
},
|
}
|
||||||
|
|
||||||
|
func showCommandHelp(c *Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func showVersion(c *Context) {
|
func showVersion(c *Context) {
|
||||||
|
Loading…
Reference in New Issue
Block a user