diff --git a/help.go b/help.go index 89f8e04..e8ccb05 100644 --- a/help.go +++ b/help.go @@ -12,28 +12,40 @@ var helpCommand = Command{ ShortName: "h", Usage: "Shows a list of commands or help for one command", Action: func(c *Context) { - helpTemplate := `NAME: - {{.Name}} - {{.Usage}} + args := c.Args() + if len(args) > 0 { + showCommandHelp(c) + } else { + showAppHelp(c) + } + }, +} + +func showAppHelp(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}} + {{range .Commands}}{{.Name}}{{with .ShortName}}, {{.}}{{end}}{{ "\t" }}{{.Usage}} + {{end}} GLOBAL OPTIONS: - {{range .Flags}}{{.}} - {{end}} + {{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() +} + +func showCommandHelp(c *Context) { } func showVersion(c *Context) {