From ef65245544538d1c4c87140a811a223a2a2a1686 Mon Sep 17 00:00:00 2001 From: Tristan Zajonc Date: Mon, 3 Aug 2015 16:51:11 -0700 Subject: [PATCH] add ArgsUsage to App and Command --- app.go | 3 +++ command.go | 5 +++++ help.go | 20 +++++++++++--------- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/app.go b/app.go index e7caec9..aadbea6 100644 --- a/app.go +++ b/app.go @@ -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, diff --git a/command.go b/command.go index 54617af..5b6cd66 100644 --- a/command.go +++ b/command.go @@ -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 diff --git a/help.go b/help.go index 66ef2fb..0855eb6 100644 --- a/help.go +++ b/help.go @@ -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() {