From 8b46886de806f530a31802bd135a808ff33d5761 Mon Sep 17 00:00:00 2001 From: Kaushal Subedi Date: Sat, 24 Oct 2015 23:37:21 -0600 Subject: [PATCH 1/2] added flag to have a custom text on the USAGE section of help --- command.go | 2 ++ help.go | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/command.go b/command.go index fac754d..500f235 100644 --- a/command.go +++ b/command.go @@ -16,6 +16,8 @@ type Command struct { Aliases []string // A short description of the usage of this command Usage string + // Custom text to show on USAGE section of help + UsageText string // A longer explanation of how the command works Description string // A short description of the arguments of this command diff --git a/help.go b/help.go index a246f63..ff7c4cb 100644 --- a/help.go +++ b/help.go @@ -15,7 +15,7 @@ var AppHelpTemplate = `NAME: {{.Name}} - {{.Usage}} USAGE: - {{.HelpName}} {{if .Flags}}[global options]{{end}}{{if .Commands}} command [command options]{{end}} {{if .ArgsUsage}}{{.ArgsUsage}}{{else}}[arguments...]{{end}} + {{if .UsageText}}{{.UsageText}}{{else}}{{.HelpName}} {{if .Flags}}[global options]{{end}}{{if .Commands}} command [command options]{{end}} {{if .ArgsUsage}}{{.ArgsUsage}}{{else}}[arguments...]{{end}}{{end}} {{if .Version}} VERSION: {{.Version}} From c70ad9b688cec7cea81b9886467987bf478bb5c5 Mon Sep 17 00:00:00 2001 From: Kaushal Subedi Date: Sat, 24 Oct 2015 23:51:06 -0600 Subject: [PATCH 2/2] fixed tests --- app.go | 3 +++ app_test.go | 1 + 2 files changed, 4 insertions(+) diff --git a/app.go b/app.go index 9a15c0c..df6ecaf 100644 --- a/app.go +++ b/app.go @@ -17,6 +17,8 @@ type App struct { HelpName string // Description of the program. Usage string + // Text to override the USAGE section of help + UsageText string // Description of the program argument format. ArgsUsage string // Version of the program @@ -73,6 +75,7 @@ func NewApp() *App { Name: os.Args[0], HelpName: os.Args[0], Usage: "A new cli application", + UsageText: "", Version: "0.0.0", BashComplete: DefaultAppComplete, Action: helpCommand.Action, diff --git a/app_test.go b/app_test.go index ada5d69..93a67d0 100644 --- a/app_test.go +++ b/app_test.go @@ -22,6 +22,7 @@ func ExampleApp() { app.Action = func(c *Context) { fmt.Printf("Hello %v\n", c.String("name")) } + app.UsageText = "app [first_arg] [second_arg]" app.Author = "Harrison" app.Email = "harrison@lolwut.com" app.Authors = []Author{Author{Name: "Oliver Allen", Email: "oliver@toyshop.com"}}