JMS #14: More help cleanup
This commit is contained in:
parent
63b9f2823a
commit
580cc011fd
4
app.go
4
app.go
@ -23,7 +23,7 @@ func NewApp() *App {
|
|||||||
Name: os.Args[0],
|
Name: os.Args[0],
|
||||||
Usage: "A new cli application",
|
Usage: "A new cli application",
|
||||||
Version: "0.0.0",
|
Version: "0.0.0",
|
||||||
Action: ShowHelp,
|
Action: helpCommand.Action,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -33,7 +33,7 @@ func (a *App) Run(arguments []string) {
|
|||||||
set.Parse(arguments[1:])
|
set.Parse(arguments[1:])
|
||||||
|
|
||||||
// append help to commands
|
// append help to commands
|
||||||
a.Commands = append(a.Commands, HelpCommand)
|
a.Commands = append(a.Commands, helpCommand)
|
||||||
|
|
||||||
context := NewContext(a, set, set)
|
context := NewContext(a, set, set)
|
||||||
args := context.Args()
|
args := context.Args()
|
||||||
|
34
help.go
34
help.go
@ -4,33 +4,31 @@ import "os"
|
|||||||
import "text/tabwriter"
|
import "text/tabwriter"
|
||||||
import "text/template"
|
import "text/template"
|
||||||
|
|
||||||
var HelpCommand = Command{
|
var helpCommand = Command{
|
||||||
Name: "help",
|
Name: "help",
|
||||||
ShortName: "h",
|
ShortName: "h",
|
||||||
Usage: "Shows a list of commands or help for one command",
|
Usage: "Shows a list of commands or help for one command",
|
||||||
Action: ShowHelp,
|
Action: func(c *Context) {
|
||||||
}
|
helpTemplate := `NAME:
|
||||||
|
{{.Name}} - {{.Usage}}
|
||||||
func ShowHelp(c *Context) {
|
|
||||||
helpTemplate := `NAME:
|
|
||||||
{{.Name}} - {{.Usage}}
|
|
||||||
|
|
||||||
USAGE:
|
USAGE:
|
||||||
{{.Name}} [global options] command [command options] [arguments...]
|
{{.Name}} [global options] command [command options] [arguments...]
|
||||||
|
|
||||||
VERSION:
|
VERSION:
|
||||||
{{.Version}}
|
{{.Version}}
|
||||||
|
|
||||||
COMMANDS:
|
COMMANDS:
|
||||||
{{range .Commands}}{{.Name}}{{with .ShortName}}, {{.}}{{end}}{{ "\t" }}{{.Usage}}
|
{{range .Commands}}{{.Name}}{{with .ShortName}}, {{.}}{{end}}{{ "\t" }}{{.Usage}}
|
||||||
{{end}}
|
{{end}}
|
||||||
GLOBAL OPTIONS
|
GLOBAL OPTIONS:
|
||||||
{{range .Flags}}{{.}}
|
{{range .Flags}}{{.}}
|
||||||
{{end}}
|
{{end}}
|
||||||
`
|
`
|
||||||
|
|
||||||
w := tabwriter.NewWriter(os.Stdout, 0, 8, 1, '\t', 0)
|
w := tabwriter.NewWriter(os.Stdout, 0, 8, 1, '\t', 0)
|
||||||
t := template.Must(template.New("help").Parse(helpTemplate))
|
t := template.Must(template.New("help").Parse(helpTemplate))
|
||||||
t.Execute(w, c.App)
|
t.Execute(w, c.App)
|
||||||
w.Flush()
|
w.Flush()
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user