2013-07-14 23:30:58 +00:00
|
|
|
package cli
|
|
|
|
|
2013-07-20 15:44:09 +00:00
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
"text/tabwriter"
|
|
|
|
"text/template"
|
|
|
|
)
|
2013-07-15 00:37:43 +00:00
|
|
|
|
2013-07-19 22:23:42 +00:00
|
|
|
var helpCommand = Command{
|
2013-07-14 23:30:58 +00:00
|
|
|
Name: "help",
|
|
|
|
ShortName: "h",
|
2013-07-15 01:17:15 +00:00
|
|
|
Usage: "Shows a list of commands or help for one command",
|
2013-07-19 22:23:42 +00:00
|
|
|
Action: func(c *Context) {
|
|
|
|
helpTemplate := `NAME:
|
|
|
|
{{.Name}} - {{.Usage}}
|
2013-07-15 00:37:43 +00:00
|
|
|
|
|
|
|
USAGE:
|
2013-07-19 22:23:42 +00:00
|
|
|
{{.Name}} [global options] command [command options] [arguments...]
|
2013-07-15 00:37:43 +00:00
|
|
|
|
|
|
|
VERSION:
|
2013-07-19 22:23:42 +00:00
|
|
|
{{.Version}}
|
2013-07-15 00:37:43 +00:00
|
|
|
|
|
|
|
COMMANDS:
|
2013-07-19 22:23:42 +00:00
|
|
|
{{range .Commands}}{{.Name}}{{with .ShortName}}, {{.}}{{end}}{{ "\t" }}{{.Usage}}
|
|
|
|
{{end}}
|
|
|
|
GLOBAL OPTIONS:
|
|
|
|
{{range .Flags}}{{.}}
|
|
|
|
{{end}}
|
2013-07-15 00:37:43 +00:00
|
|
|
`
|
|
|
|
|
2013-07-19 22:23:42 +00:00
|
|
|
w := tabwriter.NewWriter(os.Stdout, 0, 8, 1, '\t', 0)
|
|
|
|
t := template.Must(template.New("help").Parse(helpTemplate))
|
|
|
|
t.Execute(w, c.App)
|
|
|
|
w.Flush()
|
|
|
|
},
|
2013-07-14 23:30:58 +00:00
|
|
|
}
|
2013-07-20 15:44:09 +00:00
|
|
|
|
|
|
|
func showVersion(c *Context) {
|
|
|
|
fmt.Printf("%v version %v\n", c.App.Name, c.App.Version)
|
|
|
|
}
|