Skip to content

Commit 89c8946

Browse files
committed
Fix:(issue_1609) Dont show [arguments...] in usage
1 parent 68f9c2c commit 89c8946

File tree

5 files changed

+18
-10
lines changed

5 files changed

+18
-10
lines changed

args.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ type Argument interface {
6666
Usage() string
6767
}
6868

69+
// AnyArguments to differentiate between no arguments(nil) vs aleast one
70+
var AnyArguments = []Argument{nil}
71+
6972
type ArgumentBase[T any, C any, VC ValueCreator[T, C]] struct {
7073
Name string `json:"name"` // the name of this argument
7174
Value T `json:"value"` // the default value of this argument

examples_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ func ExampleCommand_Run_appHelp() {
9898
Flags: []cli.Flag{
9999
&cli.StringFlag{Name: "name", Value: "bob", Usage: "a name to say"},
100100
},
101+
Arguments: cli.AnyArguments,
101102
Commands: []*cli.Command{
102103
{
103104
Name: "describeit",
@@ -191,7 +192,7 @@ func ExampleCommand_Run_commandHelp() {
191192
}
192193

193194
func ExampleCommand_Run_noAction() {
194-
cmd := &cli.Command{Name: "greet"}
195+
cmd := &cli.Command{Name: "greet"} //, Arguments: cli.AnyArguments}
195196

196197
// Simulate the command line arguments
197198
os.Args = []string{"greet"}
@@ -202,7 +203,7 @@ func ExampleCommand_Run_noAction() {
202203
// greet - A new cli application
203204
//
204205
// USAGE:
205-
// greet [global options] [arguments...]
206+
// greet [global options]
206207
//
207208
// GLOBAL OPTIONS:
208209
// --help, -h show help

godoc-current.txt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ var (
3131
SuggestCommand SuggestCommandFunc = suggestCommand
3232
SuggestDidYouMeanTemplate string = suggestDidYouMeanTemplate
3333
)
34+
var AnyArguments = []Argument{nil}
35+
AnyArguments to differentiate between no arguments(nil) vs aleast one
36+
3437
var CommandHelpTemplate = `NAME:
3538
{{template "helpNameTemplate" .}}
3639

@@ -84,7 +87,7 @@ var RootCommandHelpTemplate = `NAME:
8487
{{template "helpNameTemplate" .}}
8588

8689
USAGE:
87-
{{if .UsageText}}{{wrap .UsageText 3}}{{else}}{{.FullName}} {{if .VisibleFlags}}[global options]{{end}}{{if .VisibleCommands}} [command [command options]]{{end}} {{if .ArgsUsage}}{{.ArgsUsage}}{{else}}[arguments...]{{end}}{{end}}{{if .Version}}{{if not .HideVersion}}
90+
{{if .UsageText}}{{wrap .UsageText 3}}{{else}}{{.FullName}} {{if .VisibleFlags}}[global options]{{end}}{{if .VisibleCommands}} [command [command options]]{{end}}{{if .ArgsUsage}} {{.ArgsUsage}}{{else}}{{if .Arguments}} [arguments...]{{end}}{{end}}{{end}}{{if .Version}}{{if not .HideVersion}}
8891

8992
VERSION:
9093
{{.Version}}{{end}}{{end}}{{if .Description}}
@@ -112,7 +115,7 @@ var SubcommandHelpTemplate = `NAME:
112115
{{template "helpNameTemplate" .}}
113116

114117
USAGE:
115-
{{if .UsageText}}{{wrap .UsageText 3}}{{else}}{{.FullName}} {{if .VisibleCommands}}[command [command options]] {{end}}{{if .ArgsUsage}}{{.ArgsUsage}}{{else}}[arguments...]{{end}}{{end}}{{if .Category}}
118+
{{if .UsageText}}{{wrap .UsageText 3}}{{else}}{{.FullName}}{{if .VisibleCommands}} [command [command options]] {{end}}{{if .ArgsUsage}} {{.ArgsUsage}}{{else}}{{if .Arguments}} [arguments...]{{end}}{{end}}{{end}}{{if .Category}}
116119

117120
CATEGORY:
118121
{{.Category}}{{end}}{{if .Description}}

help_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ func Test_Help_RequiredFlagsNoDefault(t *testing.T) {
7373
Flags: []Flag{
7474
&IntFlag{Name: "foo", Aliases: []string{"f"}, Required: true},
7575
},
76-
Writer: output,
76+
Arguments: AnyArguments,
77+
Writer: output,
7778
}
7879

7980
_ = cmd.Run(buildTestContext(t), []string{"test", "-h"})
@@ -716,7 +717,7 @@ func TestShowSubcommandHelp_GlobalOptions(t *testing.T) {
716717
foo frobbly
717718
718719
USAGE:
719-
foo frobbly [command [command options]]
720+
foo frobbly [command [command options]]
720721
721722
OPTIONS:
722723
--bar value
@@ -1719,7 +1720,7 @@ func TestCategorizedHelp(t *testing.T) {
17191720
application
17201721
17211722
USAGE:
1722-
cli.test [global options] [arguments...]
1723+
cli.test [global options]
17231724
17241725
GLOBAL OPTIONS:
17251726
--help, -h show help

template.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package cli
33
var (
44
helpNameTemplate = `{{$v := offset .FullName 6}}{{wrap .FullName 3}}{{if .Usage}} - {{wrap .Usage $v}}{{end}}`
55
argsTemplate = `{{if .Arguments}}{{range .Arguments}}{{.Usage}}{{end}}{{end}}`
6-
usageTemplate = `{{if .UsageText}}{{wrap .UsageText 3}}{{else}}{{.FullName}}{{if .VisibleFlags}} [command [command options]]{{end}} {{if .ArgsUsage}}{{.ArgsUsage}}{{else}}{{template "argsTemplate" .}}{{end}}{{end}}`
6+
usageTemplate = `{{if .UsageText}}{{wrap .UsageText 3}}{{else}}{{.FullName}}{{if .VisibleFlags}} [command [command options]]{{end}}{{if .ArgsUsage}} {{.ArgsUsage}}{{else}}{{if .Arguments}} {{template "argsTemplate" .}}{{end}}{{end}}{{end}}`
77
descriptionTemplate = `{{wrap .Description 3}}`
88
authorsTemplate = `{{with $length := len .Authors}}{{if ne 1 $length}}S{{end}}{{end}}:
99
{{range $index, $author := .Authors}}{{if $index}}
@@ -45,7 +45,7 @@ var RootCommandHelpTemplate = `NAME:
4545
{{template "helpNameTemplate" .}}
4646
4747
USAGE:
48-
{{if .UsageText}}{{wrap .UsageText 3}}{{else}}{{.FullName}} {{if .VisibleFlags}}[global options]{{end}}{{if .VisibleCommands}} [command [command options]]{{end}} {{if .ArgsUsage}}{{.ArgsUsage}}{{else}}[arguments...]{{end}}{{end}}{{if .Version}}{{if not .HideVersion}}
48+
{{if .UsageText}}{{wrap .UsageText 3}}{{else}}{{.FullName}} {{if .VisibleFlags}}[global options]{{end}}{{if .VisibleCommands}} [command [command options]]{{end}}{{if .ArgsUsage}} {{.ArgsUsage}}{{else}}{{if .Arguments}} [arguments...]{{end}}{{end}}{{end}}{{if .Version}}{{if not .HideVersion}}
4949
5050
VERSION:
5151
{{.Version}}{{end}}{{end}}{{if .Description}}
@@ -95,7 +95,7 @@ var SubcommandHelpTemplate = `NAME:
9595
{{template "helpNameTemplate" .}}
9696
9797
USAGE:
98-
{{if .UsageText}}{{wrap .UsageText 3}}{{else}}{{.FullName}} {{if .VisibleCommands}}[command [command options]] {{end}}{{if .ArgsUsage}}{{.ArgsUsage}}{{else}}[arguments...]{{end}}{{end}}{{if .Category}}
98+
{{if .UsageText}}{{wrap .UsageText 3}}{{else}}{{.FullName}}{{if .VisibleCommands}} [command [command options]] {{end}}{{if .ArgsUsage}} {{.ArgsUsage}}{{else}}{{if .Arguments}} [arguments...]{{end}}{{end}}{{end}}{{if .Category}}
9999
100100
CATEGORY:
101101
{{.Category}}{{end}}{{if .Description}}

0 commit comments

Comments
 (0)