Skip to content

Commit e7c80ce

Browse files
authored
Merge branch 'main' into fix-command-help
2 parents 159faa0 + 4dc6aa6 commit e7c80ce

15 files changed

Lines changed: 65 additions & 74 deletions

command.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ type Command struct {
9090
// default behavior.
9191
ExitErrHandler ExitErrHandlerFunc `json:"-"`
9292
// Other custom info
93-
Metadata map[string]interface{} `json:"metadata"`
93+
Metadata map[string]any `json:"metadata"`
9494
// Carries a function which returns app specific info.
9595
ExtraInfo func() map[string]string `json:"-"`
9696
// CustomRootCommandHelpTemplate the text template for app help topic.
@@ -559,7 +559,7 @@ func (cmd *Command) Count(name string) int {
559559
}
560560

561561
// Value returns the value of the flag corresponding to `name`
562-
func (cmd *Command) Value(name string) interface{} {
562+
func (cmd *Command) Value(name string) any {
563563
if fs := cmd.lookupFlag(name); fs != nil {
564564
tracef("value found for name %[1]q (cmd=%[2]q)", name, cmd.Name)
565565
return fs.Get()

command_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1973,7 +1973,7 @@ func TestCommandHelpPrinter(t *testing.T) {
19731973
}()
19741974

19751975
wasCalled := false
1976-
HelpPrinter = func(io.Writer, string, interface{}) {
1976+
HelpPrinter = func(io.Writer, string, any) {
19771977
wasCalled = true
19781978
}
19791979

@@ -5420,7 +5420,7 @@ func TestCommand_ExclusiveFlagsWithAfter(t *testing.T) {
54205420
func TestCommand_ParallelRun(t *testing.T) {
54215421
t.Parallel()
54225422

5423-
for i := 0; i < 10; i++ {
5423+
for i := range 10 {
54245424
t.Run(fmt.Sprintf("run_%d", i), func(t *testing.T) {
54255425
t.Parallel()
54265426

completion_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -69,15 +69,15 @@ func TestCompletionSubcommand(t *testing.T) {
6969
args []string
7070
contains string
7171
msg string
72-
msgArgs []interface{}
72+
msgArgs []any
7373
notContains bool
7474
}{
7575
{
7676
name: "subcommand general completion",
7777
args: []string{"foo", "bar", completionFlag},
7878
contains: "xyz",
7979
msg: "Expected output to contain shell name %[1]q",
80-
msgArgs: []interface{}{
80+
msgArgs: []any{
8181
"xyz",
8282
},
8383
},
@@ -86,7 +86,7 @@ func TestCompletionSubcommand(t *testing.T) {
8686
args: []string{"foo", "bar", "-", completionFlag},
8787
contains: "l1",
8888
msg: "Expected output to contain shell name %[1]q",
89-
msgArgs: []interface{}{
89+
msgArgs: []any{
9090
"l1",
9191
},
9292
},
@@ -95,7 +95,7 @@ func TestCompletionSubcommand(t *testing.T) {
9595
args: []string{"foo", "bar", "--", completionFlag},
9696
contains: "l1",
9797
msg: "Expected output to contain shell name %[1]q",
98-
msgArgs: []interface{}{
98+
msgArgs: []any{
9999
"l1",
100100
},
101101
notContains: true,
@@ -105,7 +105,7 @@ func TestCompletionSubcommand(t *testing.T) {
105105
args: []string{"foo", "bar", "xyz", completionFlag},
106106
contains: "-g",
107107
msg: "Expected output to contain flag %[1]q",
108-
msgArgs: []interface{}{
108+
msgArgs: []any{
109109
"-g",
110110
},
111111
notContains: true,
@@ -115,7 +115,7 @@ func TestCompletionSubcommand(t *testing.T) {
115115
args: []string{"foo", "bar", "xyz", "-", completionFlag},
116116
contains: "-g",
117117
msg: "Expected output to contain flag %[1]q",
118-
msgArgs: []interface{}{
118+
msgArgs: []any{
119119
"-g",
120120
},
121121
},
@@ -124,7 +124,7 @@ func TestCompletionSubcommand(t *testing.T) {
124124
args: []string{"foo", "bar", "xyz", "--", completionFlag},
125125
contains: "-g",
126126
msg: "Expected output to contain flag %[1]q",
127-
msgArgs: []interface{}{
127+
msgArgs: []any{
128128
"-g",
129129
},
130130
notContains: true,
@@ -134,7 +134,7 @@ func TestCompletionSubcommand(t *testing.T) {
134134
args: []string{"foo", "bar", "xyz", "--", "sargs", completionFlag},
135135
contains: "-g",
136136
msg: "Expected output to contain flag %[1]q",
137-
msgArgs: []interface{}{
137+
msgArgs: []any{
138138
"-g",
139139
},
140140
notContains: true,

docs.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,21 +35,21 @@ func unquoteUsage(usage string) (string, string) {
3535
}
3636

3737
func prefixedNames(names []string, placeholder string) string {
38-
var prefixed string
38+
var prefixed strings.Builder
3939
for i, name := range names {
4040
if name == "" {
4141
continue
4242
}
4343

44-
prefixed += prefixFor(name) + name
44+
prefixed.WriteString(prefixFor(name) + name)
4545
if placeholder != "" {
46-
prefixed += " " + placeholder
46+
prefixed.WriteString(" " + placeholder)
4747
}
4848
if i < len(names)-1 {
49-
prefixed += ", "
49+
prefixed.WriteString(", ")
5050
}
5151
}
52-
return prefixed
52+
return prefixed.String()
5353
}
5454

5555
func envFormat(envVars []string, prefix, sep, suffix string) string {

flag.go

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package cli
33
import (
44
"context"
55
"fmt"
6-
"regexp"
6+
"slices"
77
"strings"
88
"time"
99
)
@@ -16,11 +16,7 @@ const (
1616
disableSliceFlagSeparator = false
1717
)
1818

19-
var (
20-
slPfx = fmt.Sprintf("sl:::%d:::", time.Now().UTC().UnixNano())
21-
22-
commaWhitespace = regexp.MustCompile("[, ]+.*")
23-
)
19+
var slPfx = fmt.Sprintf("sl:::%d:::", time.Now().UTC().UnixNano())
2420

2521
// GenerateShellCompletionFlag enables shell completion
2622
var GenerateShellCompletionFlag Flag = &BoolFlag{
@@ -201,20 +197,18 @@ func FlagNames(name string, aliases []string) []string {
201197
// Strip off anything after the first found comma or space, which
202198
// *hopefully* makes it a tiny bit more obvious that unexpected behavior is
203199
// caused by using the v1 form of stringly typed "Name".
204-
ret = append(ret, commaWhitespace.ReplaceAllString(part, ""))
200+
if i := strings.IndexAny(part, ", "); i >= 0 {
201+
ret = append(ret, part[:i])
202+
} else {
203+
ret = append(ret, part)
204+
}
205205
}
206206

207207
return ret
208208
}
209209

210210
func hasFlag(flags []Flag, fl Flag) bool {
211-
for _, existing := range flags {
212-
if fl == existing {
213-
return true
214-
}
215-
}
216-
217-
return false
211+
return slices.Contains(flags, fl)
218212
}
219213

220214
func flagSplitMultiValues(val string, sliceSeparator string, disableSliceSeparator bool) []string {

flag_bool.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ func (b *boolValue) Set(s string) error {
6969
return err
7070
}
7171

72-
func (b *boolValue) Get() interface{} { return *b.destination }
72+
func (b *boolValue) Get() any { return *b.destination }
7373

7474
func (b *boolValue) String() string {
7575
return strconv.FormatBool(*b.destination)

flag_map_impl.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ func (i *MapBase[T, C, VC]) Value() map[string]T {
115115
}
116116

117117
// Get returns the mapping of values set by this flag
118-
func (i *MapBase[T, C, VC]) Get() interface{} {
118+
func (i *MapBase[T, C, VC]) Get() any {
119119
return *i.dict
120120
}
121121

flag_slice_base.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ func (i *SliceBase[T, C, VC]) Value() []T {
105105
}
106106

107107
// Get returns the slice of values set by this flag
108-
func (i *SliceBase[T, C, VC]) Get() interface{} {
108+
func (i *SliceBase[T, C, VC]) Get() any {
109109
return *i.slice
110110
}
111111

flag_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func (p *Parser) String() string {
3636
return fmt.Sprintf("%s,%s", p[0], p[1])
3737
}
3838

39-
func (p *Parser) Get() interface{} {
39+
func (p *Parser) Get() any {
4040
return p
4141
}
4242

godoc-current.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,7 @@ type Command struct {
499499
// default behavior.
500500
ExitErrHandler ExitErrHandlerFunc `json:"-"`
501501
// Other custom info
502-
Metadata map[string]interface{} `json:"metadata"`
502+
Metadata map[string]any `json:"metadata"`
503503
// Carries a function which returns app specific info.
504504
ExtraInfo func() map[string]string `json:"-"`
505505
// CustomRootCommandHelpTemplate the text template for app help topic.
@@ -777,7 +777,7 @@ func (cmd *Command) UintSlice(name string) []uint
777777
UintSlice looks up the value of a local UintSliceFlag, returns nil if not
778778
found
779779

780-
func (cmd *Command) Value(name string) interface{}
780+
func (cmd *Command) Value(name string) any
781781
Value returns the value of the flag corresponding to `name`
782782

783783
func (cmd *Command) VisibleCategories() []CommandCategory
@@ -1225,7 +1225,7 @@ func NewMapBase[T any, C any, VC ValueCreator[T, C]](defaults map[string]T) *Map
12251225

12261226
func (i MapBase[T, C, VC]) Create(val map[string]T, p *map[string]T, c C) Value
12271227

1228-
func (i *MapBase[T, C, VC]) Get() interface{}
1228+
func (i *MapBase[T, C, VC]) Get() any
12291229
Get returns the mapping of values set by this flag
12301230

12311231
func (i *MapBase[T, C, VC]) Serialize() string
@@ -1312,7 +1312,7 @@ func NewSliceBase[T any, C any, VC ValueCreator[T, C]](defaults ...T) *SliceBase
13121312

13131313
func (i SliceBase[T, C, VC]) Create(val []T, p *[]T, c C) Value
13141314

1315-
func (i *SliceBase[T, C, VC]) Get() interface{}
1315+
func (i *SliceBase[T, C, VC]) Get() any
13161316
Get returns the slice of values set by this flag
13171317

13181318
func (i *SliceBase[T, C, VC]) Serialize() string

0 commit comments

Comments
 (0)