From 427677aef0c3b984fa946ff9f945678cf78edebf Mon Sep 17 00:00:00 2001 From: Emiliano Deustua Date: Thu, 22 Feb 2024 12:54:32 -0500 Subject: [PATCH 1/2] fix: Fix repeated [arguments...] in usage template --- template.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/template.go b/template.go index daad470022..dea3bde001 100644 --- a/template.go +++ b/template.go @@ -1,7 +1,7 @@ package cli var helpNameTemplate = `{{$v := offset .HelpName 6}}{{wrap .HelpName 3}}{{if .Usage}} - {{wrap .Usage $v}}{{end}}` -var usageTemplate = `{{if .UsageText}}{{wrap .UsageText 3}}{{else}}{{.HelpName}}{{if .VisibleFlags}} [command options]{{end}} {{if .ArgsUsage}}{{.ArgsUsage}}{{else}}{{if .Args}}[arguments...]{{end}}[arguments...]{{end}}{{end}}` +var usageTemplate = `{{if .UsageText}}{{wrap .UsageText 3}}{{else}}{{.HelpName}}{{if .VisibleFlags}} [command options]{{end}} {{if .ArgsUsage}}{{.ArgsUsage}}{{else}}{{if .Args}}[arguments...]{{end}}{{end}}{{end}}` var descriptionTemplate = `{{wrap .Description 3}}` var authorsTemplate = `{{with $length := len .Authors}}{{if ne 1 $length}}S{{end}}{{end}}: {{range $index, $author := .Authors}}{{if $index}} From fa2b127974684dae68bcb9b3778d0a77fa91d1ce Mon Sep 17 00:00:00 2001 From: Emiliano Deustua Date: Thu, 7 Mar 2024 08:34:47 -0500 Subject: [PATCH 2/2] fix tests --- app_test.go | 6 +++++- template.go | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/app_test.go b/app_test.go index cf9680f541..5151a48223 100644 --- a/app_test.go +++ b/app_test.go @@ -167,6 +167,7 @@ func ExampleApp_Run_commandHelp() { Aliases: []string{"d"}, Usage: "use it to see a description", Description: "This is how we describe describeit the function", + Args: true, Action: func(c *Context) error { fmt.Printf("i like to describe things") return nil @@ -227,7 +228,7 @@ func ExampleApp_Run_subcommandNoAction() { // greet describeit - use it to see a description // // USAGE: - // greet describeit [command options] [arguments...] + // greet describeit [command options] // // DESCRIPTION: // This is how we describe describeit the function @@ -1912,6 +1913,7 @@ func TestApp_Run_SubcommandFullPath(t *testing.T) { subCmd := &Command{ Name: "bar", Usage: "does bar things", + Args: true, } cmd := &Command{ Name: "foo", @@ -1946,6 +1948,7 @@ func TestApp_Run_SubcommandHelpName(t *testing.T) { Name: "bar", HelpName: "custom", Usage: "does bar things", + Args: true, } cmd := &Command{ Name: "foo", @@ -1980,6 +1983,7 @@ func TestApp_Run_CommandHelpName(t *testing.T) { subCmd := &Command{ Name: "bar", Usage: "does bar things", + Args: true, } cmd := &Command{ Name: "foo", diff --git a/template.go b/template.go index dea3bde001..5748f4c201 100644 --- a/template.go +++ b/template.go @@ -1,7 +1,7 @@ package cli var helpNameTemplate = `{{$v := offset .HelpName 6}}{{wrap .HelpName 3}}{{if .Usage}} - {{wrap .Usage $v}}{{end}}` -var usageTemplate = `{{if .UsageText}}{{wrap .UsageText 3}}{{else}}{{.HelpName}}{{if .VisibleFlags}} [command options]{{end}} {{if .ArgsUsage}}{{.ArgsUsage}}{{else}}{{if .Args}}[arguments...]{{end}}{{end}}{{end}}` +var usageTemplate = `{{if .UsageText}}{{wrap .UsageText 3}}{{else}}{{.HelpName}}{{if .VisibleFlags}} [command options]{{end}}{{if .ArgsUsage}}{{.ArgsUsage}}{{else}}{{if .Args}} [arguments...]{{end}}{{end}}{{end}}` var descriptionTemplate = `{{wrap .Description 3}}` var authorsTemplate = `{{with $length := len .Authors}}{{if ne 1 $length}}S{{end}}{{end}}: {{range $index, $author := .Authors}}{{if $index}}