Skip to content

Commit b877868

Browse files
authored
Merge branch 'main' into v1.8738.0
2 parents a62f22a + eb65e6b commit b877868

104 files changed

Lines changed: 271 additions & 271 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎Makefile‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ lint:
55
./scripts/lint.sh
66

77
test:
8-
./scripts/test.sh
8+
./scripts/run-tests.sh
99

1010
fmt:
1111
golangci-lint run --fix ./...

‎core/bootstrap_test.go‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func TestInterruptError(t *testing.T) {
2121
Namespace: "test",
2222
Resource: "interrupt",
2323
Verb: "error",
24-
ArgsType: reflect.TypeOf(args.RawArgs{}),
24+
ArgsType: reflect.TypeFor[args.RawArgs](),
2525
Run: func(_ context.Context, _ any) (i any, e error) {
2626
return nil, &interactive.InterruptError{}
2727
},
@@ -38,7 +38,7 @@ func TestInterruptError(t *testing.T) {
3838
Namespace: "test",
3939
Resource: "code",
4040
Verb: "error",
41-
ArgsType: reflect.TypeOf(args.RawArgs{}),
41+
ArgsType: reflect.TypeFor[args.RawArgs](),
4242
Run: func(_ context.Context, _ any) (i any, e error) {
4343
return nil, &core.CliError{Code: 99}
4444
},
@@ -55,7 +55,7 @@ func TestInterruptError(t *testing.T) {
5555
Namespace: "test",
5656
Resource: "empty",
5757
Verb: "error",
58-
ArgsType: reflect.TypeOf(args.RawArgs{}),
58+
ArgsType: reflect.TypeFor[args.RawArgs](),
5959
Run: func(_ context.Context, _ any) (i any, e error) {
6060
return nil, &core.CliError{Code: 99, Empty: true}
6161
},
@@ -75,7 +75,7 @@ func TestInterruptError(t *testing.T) {
7575
Namespace: "test",
7676
Resource: "empty",
7777
Verb: "error",
78-
ArgsType: reflect.TypeOf(args.RawArgs{}),
78+
ArgsType: reflect.TypeFor[args.RawArgs](),
7979
Run: func(_ context.Context, _ any) (i any, e error) {
8080
return nil, &core.CliError{Code: 99, Empty: true}
8181
},
@@ -95,7 +95,7 @@ func TestInterruptError(t *testing.T) {
9595
Namespace: "test",
9696
Resource: "empty",
9797
Verb: "success",
98-
ArgsType: reflect.TypeOf(args.RawArgs{}),
98+
ArgsType: reflect.TypeFor[args.RawArgs](),
9999
Run: func(_ context.Context, _ any) (i any, e error) {
100100
return &core.SuccessResult{
101101
Empty: true,
@@ -118,7 +118,7 @@ func TestInterruptError(t *testing.T) {
118118
Namespace: "test",
119119
Resource: "empty",
120120
Verb: "success",
121-
ArgsType: reflect.TypeOf(args.RawArgs{}),
121+
ArgsType: reflect.TypeFor[args.RawArgs](),
122122
Run: func(_ context.Context, _ any) (i any, e error) {
123123
return &core.SuccessResult{
124124
Empty: true,
@@ -141,7 +141,7 @@ func TestInterruptError(t *testing.T) {
141141
Namespace: "test",
142142
Resource: "empty",
143143
Verb: "success",
144-
ArgsType: reflect.TypeOf(args.RawArgs{}),
144+
ArgsType: reflect.TypeFor[args.RawArgs](),
145145
Run: func(_ context.Context, _ any) (i any, e error) {
146146
return []int(nil), nil
147147
},

‎core/build_info_test.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import (
1717

1818
var fakeCommand = &core.Command{
1919
Namespace: "plop",
20-
ArgsType: reflect.TypeOf(args.RawArgs{}),
20+
ArgsType: reflect.TypeFor[args.RawArgs](),
2121
AllowAnonymousClient: true,
2222
Run: func(_ context.Context, _ any) (i any, e error) {
2323
return &core.SuccessResult{}, nil

‎core/checks_test.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ func TestCheckAPIKey(t *testing.T) {
2020
&core.Command{
2121
Namespace: "test",
2222
ArgSpecs: core.ArgSpecs{},
23-
ArgsType: reflect.TypeOf(testType{}),
23+
ArgsType: reflect.TypeFor[testType](),
2424
Run: func(ctx context.Context, _ any) (i any, e error) {
2525
// Test command reload the client so the profile used is the edited one
2626
return "", core.ReloadClient(ctx)

‎core/cobra_usage_builder_test.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func Test_buildUsageArgs(t *testing.T) {
4141
[additional-volumes.{index}.name] Additional volume name`
4242

4343
got := core.BuildUsageArgs(t.Context(), &core.Command{
44-
ArgsType: reflect.TypeOf(instanceListServerArgs{}),
44+
ArgsType: reflect.TypeFor[instanceListServerArgs](),
4545
ArgSpecs: core.ArgSpecs{
4646
{
4747
Name: "name",

‎core/cobra_utils_test.go‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func testGetCommands() *core.Commands {
3737
},
3838
},
3939
AllowAnonymousClient: true,
40-
ArgsType: reflect.TypeOf(testType{}),
40+
ArgsType: reflect.TypeFor[testType](),
4141
Run: func(_ context.Context, _ any) (i any, e error) {
4242
return "", nil
4343
},
@@ -55,7 +55,7 @@ func testGetCommands() *core.Commands {
5555
},
5656
},
5757
AllowAnonymousClient: true,
58-
ArgsType: reflect.TypeOf(testType{}),
58+
ArgsType: reflect.TypeFor[testType](),
5959
Run: func(_ context.Context, argsI any) (i any, e error) {
6060
return argsI, nil
6161
},
@@ -74,15 +74,15 @@ func testGetCommands() *core.Commands {
7474
},
7575
AcceptMultiplePositionalArgs: true,
7676
AllowAnonymousClient: true,
77-
ArgsType: reflect.TypeOf(testAcceptMultiPositionalArgsType{}),
77+
ArgsType: reflect.TypeFor[testAcceptMultiPositionalArgsType](),
7878
Run: func(_ context.Context, argsI any) (i any, e error) {
7979
return argsI, nil
8080
},
8181
},
8282
&core.Command{
8383
Namespace: "test",
8484
Resource: "raw-args",
85-
ArgsType: reflect.TypeOf(args.RawArgs{}),
85+
ArgsType: reflect.TypeFor[args.RawArgs](),
8686
AllowAnonymousClient: true,
8787
Run: func(_ context.Context, argsI any) (i any, e error) {
8888
rawArgs := *argsI.(*args.RawArgs)
@@ -93,7 +93,7 @@ func testGetCommands() *core.Commands {
9393
&core.Command{
9494
Namespace: "test",
9595
Resource: "date",
96-
ArgsType: reflect.TypeOf(testDate{}),
96+
ArgsType: reflect.TypeFor[testDate](),
9797
AllowAnonymousClient: true,
9898
Run: func(_ context.Context, argsI any) (i any, e error) {
9999
a := argsI.(*testDate)

‎core/human/marshal.go‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,15 @@ func Marshal(data any, opt *MarshalOpt) (string, error) {
6868
return marshalerFunc(rValue.Interface(), opt)
6969

7070
// Handle special well known interface
71-
case rType.Implements(reflect.TypeOf((*Marshaler)(nil)).Elem()):
71+
case rType.Implements(reflect.TypeFor[Marshaler]()):
7272
return rValue.Interface().(Marshaler).MarshalHuman()
7373

7474
// Handle errors
75-
case rType.Implements(reflect.TypeOf((*error)(nil)).Elem()):
75+
case rType.Implements(reflect.TypeFor[error]()):
7676
return terminal.Style(Capitalize(rValue.Interface().(error).Error()), color.FgRed), nil
7777

7878
// Handle stringers
79-
case rType.Implements(reflect.TypeOf((*fmt.Stringer)(nil)).Elem()):
79+
case rType.Implements(reflect.TypeFor[fmt.Stringer]()):
8080
return rValue.Interface().(fmt.Stringer).String(), nil
8181

8282
// If data is a pointer dereference an call Marshal again
@@ -143,7 +143,7 @@ func marshalStruct(value reflect.Value, opt *MarshalOpt) (string, error) {
143143
return [][]string{{strings.Join(keys, "."), str}}, err
144144

145145
// If data is a stringers
146-
case rType.Implements(reflect.TypeOf((*fmt.Stringer)(nil)).Elem()):
146+
case rType.Implements(reflect.TypeFor[fmt.Stringer]()):
147147
return [][]string{
148148
{strings.Join(keys, "."), value.Interface().(fmt.Stringer).String()},
149149
}, nil

‎core/human/marshal_func.go‎

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ type MarshalerFunc func(any, *MarshalOpt) (string, error)
2222
var marshalerFuncs sync.Map
2323

2424
func init() {
25-
marshalerFuncs.Store(reflect.TypeOf(int(0)), defaultMarshalerFunc)
26-
marshalerFuncs.Store(reflect.TypeOf(int32(0)), defaultMarshalerFunc)
27-
marshalerFuncs.Store(reflect.TypeOf(int64(0)), defaultMarshalerFunc)
28-
marshalerFuncs.Store(reflect.TypeOf(uint32(0)), defaultMarshalerFunc)
29-
marshalerFuncs.Store(reflect.TypeOf(uint64(0)), defaultMarshalerFunc)
30-
marshalerFuncs.Store(reflect.TypeOf(string("")), defaultMarshalerFunc)
25+
marshalerFuncs.Store(reflect.TypeFor[int](), defaultMarshalerFunc)
26+
marshalerFuncs.Store(reflect.TypeFor[int32](), defaultMarshalerFunc)
27+
marshalerFuncs.Store(reflect.TypeFor[int64](), defaultMarshalerFunc)
28+
marshalerFuncs.Store(reflect.TypeFor[uint32](), defaultMarshalerFunc)
29+
marshalerFuncs.Store(reflect.TypeFor[uint64](), defaultMarshalerFunc)
30+
marshalerFuncs.Store(reflect.TypeFor[string](), defaultMarshalerFunc)
3131
marshalerFuncs.Store(
3232
reflect.TypeOf(bool(false)),
3333
func(i any, _ *MarshalOpt) (string, error) {
@@ -40,13 +40,13 @@ func init() {
4040
},
4141
)
4242
marshalerFuncs.Store(
43-
reflect.TypeOf(time.Time{}),
43+
reflect.TypeFor[time.Time](),
4444
func(i any, _ *MarshalOpt) (string, error) {
4545
return humanize.Time(i.(time.Time)), nil
4646
},
4747
)
4848
marshalerFuncs.Store(
49-
reflect.TypeOf(&time.Time{}),
49+
reflect.TypeFor[*time.Time](),
5050
func(i any, _ *MarshalOpt) (string, error) {
5151
t := i.(*time.Time)
5252
if t == nil {
@@ -57,7 +57,7 @@ func init() {
5757
},
5858
)
5959
marshalerFuncs.Store(
60-
reflect.TypeOf(scw.Size(0)),
60+
reflect.TypeFor[scw.Size](),
6161
func(i any, _ *MarshalOpt) (string, error) {
6262
size := uint64(i.(scw.Size))
6363

@@ -69,7 +69,7 @@ func init() {
6969
},
7070
)
7171
marshalerFuncs.Store(
72-
reflect.TypeOf(new(scw.Size(0))),
72+
reflect.TypeFor[*scw.Size](),
7373
func(i any, _ *MarshalOpt) (string, error) {
7474
size := uint64(*i.(*scw.Size))
7575

@@ -81,7 +81,7 @@ func init() {
8181
},
8282
)
8383
marshalerFuncs.Store(
84-
reflect.TypeOf([]scw.Size{}),
84+
reflect.TypeFor[[]scw.Size](),
8585
func(i any, _ *MarshalOpt) (string, error) {
8686
sizes := i.([]scw.Size)
8787
strs := []string(nil)
@@ -97,19 +97,19 @@ func init() {
9797
},
9898
)
9999
marshalerFuncs.Store(
100-
reflect.TypeOf(net.IP{}),
100+
reflect.TypeFor[net.IP](),
101101
func(i any, _ *MarshalOpt) (string, error) {
102102
return fmt.Sprintf("%v", i.(net.IP)), nil
103103
},
104104
)
105105
marshalerFuncs.Store(
106-
reflect.TypeOf([]net.IP{}),
106+
reflect.TypeFor[[]net.IP](),
107107
func(i any, _ *MarshalOpt) (string, error) {
108108
return fmt.Sprintf("%v", i), nil
109109
},
110110
)
111111
marshalerFuncs.Store(
112-
reflect.TypeOf(scw.IPNet{}),
112+
reflect.TypeFor[scw.IPNet](),
113113
func(i any, _ *MarshalOpt) (string, error) {
114114
v := i.(scw.IPNet)
115115
str := v.String()
@@ -121,15 +121,15 @@ func init() {
121121
},
122122
)
123123
marshalerFuncs.Store(
124-
reflect.TypeOf(version.Version{}),
124+
reflect.TypeFor[version.Version](),
125125
func(i any, _ *MarshalOpt) (string, error) {
126126
v := i.(version.Version)
127127

128128
return v.String(), nil
129129
},
130130
)
131131
marshalerFuncs.Store(
132-
reflect.TypeOf(scw.Duration{}),
132+
reflect.TypeFor[scw.Duration](),
133133
func(i any, _ *MarshalOpt) (string, error) {
134134
v := i.(scw.Duration)
135135
const (
@@ -232,9 +232,9 @@ func isMarshalable(t reflect.Type) bool {
232232

233233
return (t.Kind() != reflect.Struct && t.Kind() != reflect.Map && t.Kind() != reflect.Pointer) ||
234234
hasMarshalerFunc ||
235-
t.Implements(reflect.TypeOf((*Marshaler)(nil)).Elem()) ||
236-
t.Implements(reflect.TypeOf((*error)(nil)).Elem()) ||
237-
t.Implements(reflect.TypeOf((*fmt.Stringer)(nil)).Elem()) ||
235+
t.Implements(reflect.TypeFor[Marshaler]()) ||
236+
t.Implements(reflect.TypeFor[error]()) ||
237+
t.Implements(reflect.TypeFor[fmt.Stringer]()) ||
238238
(t.Kind() == reflect.Pointer && isMarshalable(t.Elem()))
239239
}
240240

‎core/validate_test.go‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ func Test_ValidateDeprecated(t *testing.T) {
370370
t.Run("Deprecated", core.Test(&core.TestConfig{
371371
Commands: core.NewCommands(&core.Command{
372372
Namespace: "plop",
373-
ArgsType: reflect.TypeOf(args.RawArgs{}),
373+
ArgsType: reflect.TypeFor[args.RawArgs](),
374374
AllowAnonymousClient: true,
375375
Run: func(_ context.Context, _ any) (i any, e error) {
376376
return &core.SuccessResult{}, nil
@@ -738,7 +738,7 @@ func Test_ValidateOneOf(t *testing.T) {
738738
t.Run("Simple one-of validation check", core.Test(&core.TestConfig{
739739
Commands: core.NewCommands(&core.Command{
740740
Namespace: "oneof",
741-
ArgsType: reflect.TypeOf(args.RawArgs{}),
741+
ArgsType: reflect.TypeFor[args.RawArgs](),
742742
AllowAnonymousClient: true,
743743
Run: func(_ context.Context, _ any) (i any, e error) {
744744
return &core.SuccessResult{}, nil
@@ -763,7 +763,7 @@ func Test_ValidateOneOf(t *testing.T) {
763763
core.Test(&core.TestConfig{
764764
Commands: core.NewCommands(&core.Command{
765765
Namespace: "oneof",
766-
ArgsType: reflect.TypeOf(args.RawArgs{}),
766+
ArgsType: reflect.TypeFor[args.RawArgs](),
767767
AllowAnonymousClient: true,
768768
Run: func(_ context.Context, _ any) (i any, e error) {
769769
return &core.SuccessResult{}, nil
@@ -792,7 +792,7 @@ func Test_ValidateOneOf(t *testing.T) {
792792
core.Test(&core.TestConfig{
793793
Commands: core.NewCommands(&core.Command{
794794
Namespace: "oneof",
795-
ArgsType: reflect.TypeOf(args.RawArgs{}),
795+
ArgsType: reflect.TypeFor[args.RawArgs](),
796796
AllowAnonymousClient: true,
797797
Run: func(_ context.Context, _ any) (i any, e error) {
798798
return &core.SuccessResult{}, nil

‎internal/args/args_test.go‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -193,47 +193,47 @@ func TestGetArgType(t *testing.T) {
193193
}
194194

195195
t.Run("Simple", run(&TestCase{
196-
ArgType: reflect.TypeOf(&Basic{}),
196+
ArgType: reflect.TypeFor[*Basic](),
197197
Name: "string",
198198
ExpectedKind: reflect.String,
199199
}))
200200
t.Run("Simple int", run(&TestCase{
201-
ArgType: reflect.TypeOf(&Basic{}),
201+
ArgType: reflect.TypeFor[*Basic](),
202202
Name: "int-64",
203203
ExpectedKind: reflect.Int64,
204204
}))
205205
t.Run("Ptr", run(&TestCase{
206-
ArgType: reflect.TypeOf(&Basic{}),
206+
ArgType: reflect.TypeFor[*Basic](),
207207
Name: "string-ptr",
208208
ExpectedKind: reflect.String,
209209
}))
210210
t.Run("simple slice", run(&TestCase{
211-
ArgType: reflect.TypeOf(&Slice{}),
211+
ArgType: reflect.TypeFor[*Slice](),
212212
Name: "strings.{index}",
213213
ExpectedKind: reflect.String,
214214
}))
215215
t.Run("simple slice ptr", run(&TestCase{
216-
ArgType: reflect.TypeOf(&Slice{}),
216+
ArgType: reflect.TypeFor[*Slice](),
217217
Name: "slice-ptr.{index}",
218218
ExpectedKind: reflect.String,
219219
}))
220220
t.Run("nested simple", run(&TestCase{
221-
ArgType: reflect.TypeOf(&Nested{}),
221+
ArgType: reflect.TypeFor[*Nested](),
222222
Name: "basic.string",
223223
ExpectedKind: reflect.String,
224224
}))
225225
t.Run("nested empty", run(&TestCase{
226-
ArgType: reflect.TypeOf(&Nested{}),
226+
ArgType: reflect.TypeFor[*Nested](),
227227
Name: "empty",
228228
ExpectedKind: reflect.Struct,
229229
}))
230230
t.Run("merge simple", run(&TestCase{
231-
ArgType: reflect.TypeOf(&Merge{}),
231+
ArgType: reflect.TypeFor[*Merge](),
232232
Name: "merge1",
233233
ExpectedKind: reflect.String,
234234
}))
235235
t.Run("merge simple all", run(&TestCase{
236-
ArgType: reflect.TypeOf(&Merge{}),
236+
ArgType: reflect.TypeFor[*Merge](),
237237
Name: "all",
238238
ExpectedKind: reflect.String,
239239
}))

0 commit comments

Comments
 (0)