From 580cc011fde9db42be2fcd002d76329a01d16332 Mon Sep 17 00:00:00 2001 From: Jeremy Saenz Date: Fri, 19 Jul 2013 15:23:42 -0700 Subject: [PATCH] JMS #14: More help cleanup --- app.go | 4 ++-- help.go | 34 ++++++++++++++++------------------ 2 files changed, 18 insertions(+), 20 deletions(-) diff --git a/app.go b/app.go index 974ecd6..9e540b2 100644 --- a/app.go +++ b/app.go @@ -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() diff --git a/help.go b/help.go index 7d5a0c1..39f7d7f 100644 --- a/help.go +++ b/help.go @@ -4,33 +4,31 @@ 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) { - helpTemplate := `NAME: - {{.Name}} - {{.Usage}} + Action: func(c *Context) { + helpTemplate := `NAME: + {{.Name}} - {{.Usage}} USAGE: - {{.Name}} [global options] command [command options] [arguments...] + {{.Name}} [global options] command [command options] [arguments...] VERSION: - {{.Version}} + {{.Version}} COMMANDS: - {{range .Commands}}{{.Name}}{{with .ShortName}}, {{.}}{{end}}{{ "\t" }}{{.Usage}} - {{end}} -GLOBAL OPTIONS - {{range .Flags}}{{.}} - {{end}} + {{range .Commands}}{{.Name}}{{with .ShortName}}, {{.}}{{end}}{{ "\t" }}{{.Usage}} + {{end}} +GLOBAL OPTIONS: + {{range .Flags}}{{.}} + {{end}} ` - 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() + 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() + }, }