cmd/utils: improve CLI help templates

Help for a specific command now shows available subcommands.
This commit is contained in:
Felix Lange 2015-03-10 16:44:48 +01:00
parent 221fae4112
commit 972e2c1e31
1 changed files with 27 additions and 0 deletions

View File

@ -24,11 +24,38 @@ import (
"github.com/ethereum/go-ethereum/xeth" "github.com/ethereum/go-ethereum/xeth"
) )
func init() {
cli.AppHelpTemplate = `{{.Name}} {{if .Flags}}[global options] {{end}}command{{if .Flags}} [command options]{{end}} [arguments...]
VERSION:
{{.Version}}
COMMANDS:
{{range .Commands}}{{.Name}}{{with .ShortName}}, {{.}}{{end}}{{ "\t" }}{{.Usage}}
{{end}}{{if .Flags}}
GLOBAL OPTIONS:
{{range .Flags}}{{.}}
{{end}}{{end}}
`
cli.CommandHelpTemplate = `{{.Name}}{{if .Subcommands}} command{{end}}{{if .Flags}} [command options]{{end}} [arguments...]
{{if .Description}}{{.Description}}
{{end}}{{if .Subcommands}}
SUBCOMMANDS:
{{range .Subcommands}}{{.Name}}{{with .ShortName}}, {{.}}{{end}}{{ "\t" }}{{.Usage}}
{{end}}{{end}}{{if .Flags}}
OPTIONS:
{{range .Flags}}{{.}}
{{end}}{{end}}
`
}
// NewApp creates an app with sane defaults. // NewApp creates an app with sane defaults.
func NewApp(version, usage string) *cli.App { func NewApp(version, usage string) *cli.App {
app := cli.NewApp() app := cli.NewApp()
app.Name = path.Base(os.Args[0]) app.Name = path.Base(os.Args[0])
app.Author = "" app.Author = ""
app.Authors = nil
app.Email = "" app.Email = ""
app.Version = version app.Version = version
app.Usage = usage app.Usage = usage