Skip to content

Commit 1d45fd3

Browse files
committed
Replace interface{} with any
The any alias was introduced in Go 1.18. This is a purely stylistic change that makes code more readable. Changes in .go files generated by modernize -any -fix ./... PS godoc-current.txt and testdata/godoc-v3.x.txt modified accordingly. Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
1 parent 23645f3 commit 1d45fd3

10 files changed

Lines changed: 41 additions & 41 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: 1 addition & 1 deletion
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

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,

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

help_test.go

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,7 @@ func TestShowCommandHelp_HelpPrinter(t *testing.T) {
481481
{
482482
name: "no-command",
483483
template: "",
484-
printer: func(w io.Writer, _ string, _ interface{}) {
484+
printer: func(w io.Writer, _ string, _ any) {
485485
fmt.Fprint(w, "yo")
486486
},
487487
command: "",
@@ -517,7 +517,7 @@ func TestShowCommandHelp_HelpPrinter(t *testing.T) {
517517
defer func(old HelpPrinterFunc) {
518518
HelpPrinter = old
519519
}(HelpPrinter)
520-
HelpPrinter = func(w io.Writer, templ string, data interface{}) {
520+
HelpPrinter = func(w io.Writer, templ string, data any) {
521521
assert.Equal(t, tt.wantTemplate, templ, "template mismatch")
522522
tt.printer(w, templ, data)
523523
}
@@ -947,7 +947,7 @@ func TestShowRootCommandHelp_HelpPrinter(t *testing.T) {
947947
{
948948
name: "standard-command",
949949
template: "",
950-
printer: func(w io.Writer, _ string, _ interface{}) {
950+
printer: func(w io.Writer, _ string, _ any) {
951951
fmt.Fprint(w, "yo")
952952
},
953953
wantTemplate: RootCommandHelpTemplate,
@@ -956,7 +956,7 @@ func TestShowRootCommandHelp_HelpPrinter(t *testing.T) {
956956
{
957957
name: "custom-template-command",
958958
template: "{{doublecho .Name}}",
959-
printer: func(w io.Writer, templ string, data interface{}) {
959+
printer: func(w io.Writer, templ string, data any) {
960960
// Pass a custom function to ensure it gets used
961961
fm := map[string]any{"doublecho": doublecho}
962962
DefaultPrintHelpCustom(w, templ, data, fm)
@@ -971,7 +971,7 @@ func TestShowRootCommandHelp_HelpPrinter(t *testing.T) {
971971
defer func(old HelpPrinterFunc) {
972972
HelpPrinter = old
973973
}(HelpPrinter)
974-
HelpPrinter = func(w io.Writer, templ string, data interface{}) {
974+
HelpPrinter = func(w io.Writer, templ string, data any) {
975975
assert.Equal(t, tt.wantTemplate, templ, "unexpected template")
976976
tt.printer(w, templ, data)
977977
}
@@ -1006,7 +1006,7 @@ func TestShowRootCommandHelp_HelpPrinterCustom(t *testing.T) {
10061006
{
10071007
name: "standard-command",
10081008
template: "",
1009-
printer: func(w io.Writer, _ string, _ interface{}, _ map[string]interface{}) {
1009+
printer: func(w io.Writer, _ string, _ any, _ map[string]any) {
10101010
fmt.Fprint(w, "yo")
10111011
},
10121012
wantTemplate: RootCommandHelpTemplate,
@@ -1015,7 +1015,7 @@ func TestShowRootCommandHelp_HelpPrinterCustom(t *testing.T) {
10151015
{
10161016
name: "custom-template-command",
10171017
template: "{{doublecho .Name}}",
1018-
printer: func(w io.Writer, templ string, data interface{}, _ map[string]interface{}) {
1018+
printer: func(w io.Writer, templ string, data any, _ map[string]any) {
10191019
// Pass a custom function to ensure it gets used
10201020
fm := map[string]any{"doublecho": doublecho}
10211021
DefaultPrintHelpCustom(w, templ, data, fm)
@@ -1030,7 +1030,7 @@ func TestShowRootCommandHelp_HelpPrinterCustom(t *testing.T) {
10301030
defer func(old HelpPrinterCustomFunc) {
10311031
HelpPrinterCustom = old
10321032
}(HelpPrinterCustom)
1033-
HelpPrinterCustom = func(w io.Writer, templ string, data interface{}, fm map[string]interface{}) {
1033+
HelpPrinterCustom = func(w io.Writer, templ string, data any, fm map[string]any) {
10341034
assert.Nil(t, fm, "unexpected function map passed")
10351035
assert.Equal(t, tt.wantTemplate, templ, "unexpected template")
10361036
tt.printer(w, templ, data, fm)
@@ -1514,8 +1514,8 @@ Including newlines.
15141514
And then another long line. Blah blah blah does anybody ever read these things?`,
15151515
}
15161516

1517-
HelpPrinter = func(w io.Writer, templ string, data interface{}) {
1518-
funcMap := map[string]interface{}{
1517+
HelpPrinter = func(w io.Writer, templ string, data any) {
1518+
funcMap := map[string]any{
15191519
"wrapAt": func() int {
15201520
return 30
15211521
},
@@ -1597,8 +1597,8 @@ func TestWrappedCommandHelp(t *testing.T) {
15971597
cmd.setupDefaults([]string{"cli.test"})
15981598
cmd.setupCommandGraph()
15991599

1600-
HelpPrinter = func(w io.Writer, templ string, data interface{}) {
1601-
funcMap := map[string]interface{}{
1600+
HelpPrinter = func(w io.Writer, templ string, data any) {
1601+
funcMap := map[string]any{
16021602
"wrapAt": func() int {
16031603
return 30
16041604
},
@@ -1665,8 +1665,8 @@ func TestWrappedSubcommandHelp(t *testing.T) {
16651665
},
16661666
}
16671667

1668-
HelpPrinter = func(w io.Writer, templ string, data interface{}) {
1669-
funcMap := map[string]interface{}{
1668+
HelpPrinter = func(w io.Writer, templ string, data any) {
1669+
funcMap := map[string]any{
16701670
"wrapAt": func() int {
16711671
return 30
16721672
},
@@ -1737,8 +1737,8 @@ func TestWrappedHelpSubcommand(t *testing.T) {
17371737
},
17381738
}
17391739

1740-
HelpPrinter = func(w io.Writer, templ string, data interface{}) {
1741-
funcMap := map[string]interface{}{
1740+
HelpPrinter = func(w io.Writer, templ string, data any) {
1741+
funcMap := map[string]any{
17421742
"wrapAt": func() int {
17431743
return 30
17441744
},
@@ -1821,8 +1821,8 @@ func TestCategorizedHelp(t *testing.T) {
18211821
},
18221822
}
18231823

1824-
HelpPrinter = func(w io.Writer, templ string, data interface{}) {
1825-
funcMap := map[string]interface{}{
1824+
HelpPrinter = func(w io.Writer, templ string, data any) {
1825+
funcMap := map[string]any{
18261826
"wrapAt": func() int {
18271827
return 30
18281828
},

testdata/godoc-v3.x.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)