Skip to content

Commit

Permalink
JMS #14: More help cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
codegangsta committed Jul 19, 2013
1 parent 63b9f28 commit 580cc01
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 20 deletions.
4 changes: 2 additions & 2 deletions app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}

Expand All @@ -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()
Expand Down
34 changes: 16 additions & 18 deletions help.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
},
}

0 comments on commit 580cc01

Please sign in to comment.