Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ formatters:
- gofumpt # Gofumpt checks whether code was gofumpt-ed. [fast: true, auto-fix: true]
- goimports # In addition to fixing imports, goimports also formats your code in the same style as gofmt. [fast: true, auto-fix: true]
- golines
settings:
gofmt:
rewrite-rules:
- pattern: interface{}
replacement: any

linters:
default: none
Expand Down
2 changes: 1 addition & 1 deletion cmd/scw/web_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func Test_WebValidateTemplatesVariables(t *testing.T) {
if err != nil {
continue
}
var args interface{}
var args any
if cmd.ArgsType != nil {
args = reflect.New(cmd.ArgsType).Interface()
}
Expand Down
2 changes: 1 addition & 1 deletion core/arg_file_content.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
)

// loadArgsFileContent will hydrate args with default values.
func loadArgsFileContent(cmd *Command, cmdArgs interface{}) error {
func loadArgsFileContent(cmd *Command, cmdArgs any) error {
for _, argSpec := range cmd.ArgSpecs {
if !argSpec.CanLoadFile {
continue
Expand Down
4 changes: 2 additions & 2 deletions core/arg_specs.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ func ZoneArgSpec(zones ...scw.Zone) *ArgSpec {
Name: "zone",
Short: "Zone to target. If none is passed will use default zone from the config",
EnumValues: enumValues,
ValidateFunc: func(_ *ArgSpec, value interface{}) error {
ValidateFunc: func(_ *ArgSpec, value any) error {
for _, zone := range zones {
if value.(scw.Zone) == zone {
return nil
Expand Down Expand Up @@ -179,7 +179,7 @@ func RegionArgSpec(regions ...scw.Region) *ArgSpec {
Name: "region",
Short: "Region to target. If none is passed will use default region from the config",
EnumValues: enumValues,
ValidateFunc: func(_ *ArgSpec, value interface{}) error {
ValidateFunc: func(_ *ArgSpec, value any) error {
for _, region := range regions {
if value.(scw.Region) == region {
return nil
Expand Down
6 changes: 3 additions & 3 deletions core/autocomplete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func testAutocompleteGetCommands() *core.Commands {
EnumValues: []string{"S", "M", "L", "XL", "XXL"},
},
},
WaitFunc: func(_ context.Context, _, _ interface{}) (interface{}, error) {
WaitFunc: func(_ context.Context, _, _ any) (any, error) {
return nil, nil
},
},
Expand Down Expand Up @@ -573,7 +573,7 @@ func TestAutocompleteArgs(t *testing.T) {
Verb: "list",
ArgsType: reflect.TypeOf(struct{}{}),
ArgSpecs: core.ArgSpecs{},
Run: func(_ context.Context, _ interface{}) (interface{}, error) {
Run: func(_ context.Context, _ any) (any, error) {
return []*struct {
Name string
}{
Expand All @@ -592,7 +592,7 @@ func TestAutocompleteArgs(t *testing.T) {
Verb: "list",
ArgsType: reflect.TypeOf(struct{}{}),
ArgSpecs: core.ArgSpecs{},
Run: func(_ context.Context, _ interface{}) (interface{}, error) {
Run: func(_ context.Context, _ any) (any, error) {
return []*struct {
Name string
}{
Expand Down
2 changes: 1 addition & 1 deletion core/autocomplete_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ func AutocompleteGetArg(
}

if listCmd.Interceptor == nil {
listCmd.Interceptor = func(ctx context.Context, argsI interface{}, runner CommandRunner) (interface{}, error) {
listCmd.Interceptor = func(ctx context.Context, argsI any, runner CommandRunner) (any, error) {
return runner(ctx, argsI)
}
}
Expand Down
2 changes: 1 addition & 1 deletion core/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ type BootstrapConfig struct {
// Bootstrap is the main entry point. It is directly called from main.
// BootstrapConfig.Args is usually os.Args
// BootstrapConfig.Commands is a list of command available in CLI.
func Bootstrap(config *BootstrapConfig) (exitCode int, result interface{}, err error) {
func Bootstrap(config *BootstrapConfig) (exitCode int, result any, err error) {
// Handles Flags
var debug bool
var profileFlag string
Expand Down
14 changes: 7 additions & 7 deletions core/bootstrap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func TestInterruptError(t *testing.T) {
Resource: "interrupt",
Verb: "error",
ArgsType: reflect.TypeOf(args.RawArgs{}),
Run: func(_ context.Context, _ interface{}) (i interface{}, e error) {
Run: func(_ context.Context, _ any) (i any, e error) {
return nil, &interactive.InterruptError{}
},
},
Expand All @@ -38,7 +38,7 @@ func TestInterruptError(t *testing.T) {
Resource: "code",
Verb: "error",
ArgsType: reflect.TypeOf(args.RawArgs{}),
Run: func(_ context.Context, _ interface{}) (i interface{}, e error) {
Run: func(_ context.Context, _ any) (i any, e error) {
return nil, &core.CliError{Code: 99}
},
},
Expand All @@ -55,7 +55,7 @@ func TestInterruptError(t *testing.T) {
Resource: "empty",
Verb: "error",
ArgsType: reflect.TypeOf(args.RawArgs{}),
Run: func(_ context.Context, _ interface{}) (i interface{}, e error) {
Run: func(_ context.Context, _ any) (i any, e error) {
return nil, &core.CliError{Code: 99, Empty: true}
},
},
Expand All @@ -75,7 +75,7 @@ func TestInterruptError(t *testing.T) {
Resource: "empty",
Verb: "error",
ArgsType: reflect.TypeOf(args.RawArgs{}),
Run: func(_ context.Context, _ interface{}) (i interface{}, e error) {
Run: func(_ context.Context, _ any) (i any, e error) {
return nil, &core.CliError{Code: 99, Empty: true}
},
},
Expand All @@ -95,7 +95,7 @@ func TestInterruptError(t *testing.T) {
Resource: "empty",
Verb: "success",
ArgsType: reflect.TypeOf(args.RawArgs{}),
Run: func(_ context.Context, _ interface{}) (i interface{}, e error) {
Run: func(_ context.Context, _ any) (i any, e error) {
return &core.SuccessResult{
Empty: true,
Message: "dummy",
Expand All @@ -118,7 +118,7 @@ func TestInterruptError(t *testing.T) {
Resource: "empty",
Verb: "success",
ArgsType: reflect.TypeOf(args.RawArgs{}),
Run: func(_ context.Context, _ interface{}) (i interface{}, e error) {
Run: func(_ context.Context, _ any) (i any, e error) {
return &core.SuccessResult{
Empty: true,
Message: "dummy",
Expand All @@ -141,7 +141,7 @@ func TestInterruptError(t *testing.T) {
Resource: "empty",
Verb: "success",
ArgsType: reflect.TypeOf(args.RawArgs{}),
Run: func(_ context.Context, _ interface{}) (i interface{}, e error) {
Run: func(_ context.Context, _ any) (i any, e error) {
return []int(nil), nil
},
AllowAnonymousClient: true,
Expand Down
2 changes: 1 addition & 1 deletion core/build_info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ var fakeCommand = &core.Command{
Namespace: "plop",
ArgsType: reflect.TypeOf(args.RawArgs{}),
AllowAnonymousClient: true,
Run: func(_ context.Context, _ interface{}) (i interface{}, e error) {
Run: func(_ context.Context, _ any) (i any, e error) {
return &core.SuccessResult{}, nil
},
}
Expand Down
2 changes: 1 addition & 1 deletion core/checks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func TestCheckAPIKey(t *testing.T) {
Namespace: "test",
ArgSpecs: core.ArgSpecs{},
ArgsType: reflect.TypeOf(testType{}),
Run: func(ctx context.Context, _ interface{}) (i interface{}, e error) {
Run: func(ctx context.Context, _ any) (i any, e error) {
// Test command reload the client so the profile used is the edited one
return "", core.ReloadClient(ctx)
},
Expand Down
4 changes: 2 additions & 2 deletions core/cobra_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ func run(
cobraCmd *cobra.Command,
cmd *Command,
rawArgs []string,
) (interface{}, error) {
) (any, error) {
var err error

// create a new Args interface{}
Expand Down Expand Up @@ -202,7 +202,7 @@ func run(
data, err := interceptor(
ctx,
cmdArgs,
func(ctx context.Context, argsI interface{}) (i interface{}, err error) {
func(ctx context.Context, argsI any) (i any, err error) {
return cmd.Run(ctx, argsI)
},
)
Expand Down
10 changes: 5 additions & 5 deletions core/cobra_utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func testGetCommands() *core.Commands {
},
AllowAnonymousClient: true,
ArgsType: reflect.TypeOf(testType{}),
Run: func(_ context.Context, _ interface{}) (i interface{}, e error) {
Run: func(_ context.Context, _ any) (i any, e error) {
return "", nil
},
},
Expand All @@ -55,7 +55,7 @@ func testGetCommands() *core.Commands {
},
AllowAnonymousClient: true,
ArgsType: reflect.TypeOf(testType{}),
Run: func(_ context.Context, argsI interface{}) (i interface{}, e error) {
Run: func(_ context.Context, argsI any) (i any, e error) {
return argsI, nil
},
},
Expand All @@ -74,7 +74,7 @@ func testGetCommands() *core.Commands {
AcceptMultiplePositionalArgs: true,
AllowAnonymousClient: true,
ArgsType: reflect.TypeOf(testAcceptMultiPositionalArgsType{}),
Run: func(_ context.Context, argsI interface{}) (i interface{}, e error) {
Run: func(_ context.Context, argsI any) (i any, e error) {
return argsI, nil
},
},
Expand All @@ -83,7 +83,7 @@ func testGetCommands() *core.Commands {
Resource: "raw-args",
ArgsType: reflect.TypeOf(args.RawArgs{}),
AllowAnonymousClient: true,
Run: func(_ context.Context, argsI interface{}) (i interface{}, e error) {
Run: func(_ context.Context, argsI any) (i any, e error) {
res := ""
rawArgs := *argsI.(*args.RawArgs)
for i, arg := range rawArgs {
Expand All @@ -101,7 +101,7 @@ func testGetCommands() *core.Commands {
Resource: "date",
ArgsType: reflect.TypeOf(testDate{}),
AllowAnonymousClient: true,
Run: func(_ context.Context, argsI interface{}) (i interface{}, e error) {
Run: func(_ context.Context, argsI any) (i any, e error) {
a := argsI.(*testDate)

return a.Date, nil
Expand Down
8 changes: 4 additions & 4 deletions core/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,17 +95,17 @@ type Command struct {
}

// CommandPreValidateFunc allows to manipulate args before validation.
type CommandPreValidateFunc func(ctx context.Context, argsI interface{}) error
type CommandPreValidateFunc func(ctx context.Context, argsI any) error

// CommandInterceptor allow to intercept and manipulate a runner arguments and return value.
// It can for example be used to change arguments type or catch runner errors.
type CommandInterceptor func(ctx context.Context, argsI interface{}, runner CommandRunner) (interface{}, error)
type CommandInterceptor func(ctx context.Context, argsI any, runner CommandRunner) (any, error)

// CommandRunner returns the command response or an error.
type CommandRunner func(ctx context.Context, argsI interface{}) (interface{}, error)
type CommandRunner func(ctx context.Context, argsI any) (any, error)

// WaitFunc returns the updated response (respI if unchanged) or an error.
type WaitFunc func(ctx context.Context, argsI, respI interface{}) (interface{}, error)
type WaitFunc func(ctx context.Context, argsI, respI any) (any, error)

const indexCommandSeparator = "."

Expand Down
12 changes: 6 additions & 6 deletions core/command_interceptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ func CombineCommandInterceptor(interceptors ...CommandInterceptor) CommandInterc
}

previousInterceptor := combinedInterceptors
combinedInterceptors = func(ctx context.Context, args interface{}, runner CommandRunner) (interface{}, error) {
combinedInterceptors = func(ctx context.Context, args any, runner CommandRunner) (any, error) {
return previousInterceptor(
ctx,
args,
func(ctx context.Context, _ interface{}) (interface{}, error) {
func(ctx context.Context, _ any) (any, error) {
return localInterceptor(ctx, args, runner)
},
)
Expand All @@ -43,9 +43,9 @@ func CombineCommandInterceptor(interceptors ...CommandInterceptor) CommandInterc
// sdkStdErrorInterceptor is a command interceptor that will catch sdk standard error and return more friendly CLI error.
func sdkStdErrorInterceptor(
ctx context.Context,
args interface{},
args any,
runner CommandRunner,
) (interface{}, error) {
) (any, error) {
res, err := runner(ctx, args)
switch sdkError := err.(type) {
case *scw.ResourceNotFoundError:
Expand Down Expand Up @@ -130,9 +130,9 @@ func sdkStdErrorInterceptor(
// sdkStdErrorInterceptor is a command interceptor that will catch sdk standard error and return more friendly CLI error.
func sdkStdTypeInterceptor(
ctx context.Context,
args interface{},
args any,
runner CommandRunner,
) (interface{}, error) {
) (any, error) {
res, err := runner(ctx, args)
if err != nil {
return res, err
Expand Down
4 changes: 2 additions & 2 deletions core/command_interceptor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ import (
)

func Test_CombineCommandInterceptor(t *testing.T) {
runner := func(context.Context, interface{}) (interface{}, error) {
runner := func(context.Context, any) (any, error) {
return []string{"runner"}, nil
}

newInterceptor := func(name string) core.CommandInterceptor {
return func(ctx context.Context, args interface{}, runner core.CommandRunner) (interface{}, error) {
return func(ctx context.Context, args any, runner core.CommandRunner) (any, error) {
res, _ := runner(ctx, args)

return append([]string{name}, res.([]string)...), nil
Expand Down
2 changes: 1 addition & 1 deletion core/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ type Meta struct {
stdout io.Writer
stderr io.Writer
stdin io.Reader
result interface{}
result any
httpClient *http.Client
isClientFromBootstrapConfig bool
BetaMode bool
Expand Down
2 changes: 1 addition & 1 deletion core/human/marshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type Marshaler interface {
MarshalHuman() (string, error)
}

func Marshal(data interface{}, opt *MarshalOpt) (string, error) {
func Marshal(data any, opt *MarshalOpt) (string, error) {
if opt == nil {
opt = &MarshalOpt{}
}
Expand Down
Loading
Loading