add ArgsUsage to App and Command

main
Tristan Zajonc 9 years ago
parent 142e6cd241
commit ef65245544

@ -15,6 +15,8 @@ type App struct {
Name string
// Description of the program.
Usage string
// Description of the program argument format.
ArgsUsage string
// Version of the program
Version string
// List of commands to execute
@ -68,6 +70,7 @@ func NewApp() *App {
return &App{
Name: os.Args[0],
Usage: "A new cli application",
ArgsUsage: "[arguments...]",
Version: "0.0.0",
BashComplete: DefaultAppComplete,
Action: helpCommand.Action,

@ -18,6 +18,8 @@ type Command struct {
Usage string
// A longer explanation of how the command works
Description string
// A short description of the arguments of this command
ArgsUsage string
// The function to call when checking for bash command completions
BashComplete func(context *Context)
// An action to execute before any sub-subcommands are run, but after the context is ready
@ -158,6 +160,9 @@ func (c Command) startApp(ctx *Context) error {
} else {
app.Usage = c.Usage
}
if c.ArgsUsage == "" {
c.ArgsUsage = "[arguments...]"
}
// set CommandNotFound
app.CommandNotFound = ctx.App.CommandNotFound

@ -15,7 +15,7 @@ var AppHelpTemplate = `NAME:
{{.Name}} - {{.Usage}}
USAGE:
{{.Name}} {{if .Flags}}[global options]{{end}}{{if .Commands}} command [command options]{{end}} [arguments...]
{{.Name}} {{if .Flags}}[global options]{{end}}{{if .Commands}} command [command options]{{end}} {{.ArgsUsage}}
{{if .Version}}
VERSION:
{{.Version}}
@ -41,7 +41,7 @@ var CommandHelpTemplate = `NAME:
{{.FullName}} - {{.Usage}}
USAGE:
command {{.FullName}}{{if .Flags}} [command options]{{end}} [arguments...]{{if .Description}}
command {{.FullName}}{{if .Flags}} [command options]{{end}} {{.ArgsUsage}}{{if .Description}}
DESCRIPTION:
{{.Description}}{{end}}{{if .Flags}}
@ -58,7 +58,7 @@ var SubcommandHelpTemplate = `NAME:
{{.Name}} - {{.Usage}}
USAGE:
{{.Name}} command{{if .Flags}} [command options]{{end}} [arguments...]
{{.Name}} command{{if .Flags}} [command options]{{end}} {{.ArgsUsage}}
COMMANDS:
{{range .Commands}}{{join .Names ", "}}{{ "\t" }}{{.Usage}}
@ -69,9 +69,10 @@ OPTIONS:
`
var helpCommand = Command{
Name: "help",
Aliases: []string{"h"},
Usage: "Shows a list of commands or help for one command",
Name: "help",
Aliases: []string{"h"},
Usage: "Shows a list of commands or help for one command",
ArgsUsage: "[command]",
Action: func(c *Context) {
args := c.Args()
if args.Present() {
@ -83,9 +84,10 @@ var helpCommand = Command{
}
var helpSubcommand = Command{
Name: "help",
Aliases: []string{"h"},
Usage: "Shows a list of commands or help for one command",
Name: "help",
Aliases: []string{"h"},
Usage: "Shows a list of commands or help for one command",
ArgsUsage: "[command]",
Action: func(c *Context) {
args := c.Args()
if args.Present() {

Loading…
Cancel
Save