JMS #14: More help cleanup

main
Jeremy Saenz 11 years ago
parent 63b9f2823a
commit 580cc011fd

@ -23,7 +23,7 @@ func NewApp() *App {
Name: os.Args[0],
Usage: "A new cli application",
Version: "0.0.0",
Action: ShowHelp,
Action: helpCommand.Action,
}
}
@ -33,7 +33,7 @@ func (a *App) Run(arguments []string) {
set.Parse(arguments[1:])
// append help to commands
a.Commands = append(a.Commands, HelpCommand)
a.Commands = append(a.Commands, helpCommand)
context := NewContext(a, set, set)
args := context.Args()

@ -4,14 +4,11 @@ import "os"
import "text/tabwriter"
import "text/template"
var HelpCommand = Command{
var helpCommand = Command{
Name: "help",
ShortName: "h",
Usage: "Shows a list of commands or help for one command",
Action: ShowHelp,
}
func ShowHelp(c *Context) {
Action: func(c *Context) {
helpTemplate := `NAME:
{{.Name}} - {{.Usage}}
@ -24,7 +21,7 @@ VERSION:
COMMANDS:
{{range .Commands}}{{.Name}}{{with .ShortName}}, {{.}}{{end}}{{ "\t" }}{{.Usage}}
{{end}}
GLOBAL OPTIONS
GLOBAL OPTIONS:
{{range .Flags}}{{.}}
{{end}}
`
@ -33,4 +30,5 @@ GLOBAL OPTIONS
t := template.Must(template.New("help").Parse(helpTemplate))
t.Execute(w, c.App)
w.Flush()
},
}

Loading…
Cancel
Save