Skip to content

chore: enable fix_fieldalignment #4642

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
4 changes: 4 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ linters-settings:
gosec:
excludes:
- G115
govet:
enable:
- fieldalignment


issues:
exclude-dirs:
Expand Down
4 changes: 2 additions & 2 deletions cmd/scw/web_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ func Test_WebValidateTemplates(t *testing.T) {

// Test that web urls are valid templates
type failedTemplate struct {
Cmd string
Err error
Cmd string
}
errs := []any(nil)

Expand All @@ -41,8 +41,8 @@ func Test_WebValidateTemplatesVariables(t *testing.T) {

// Test that web urls are valid templates
type failedTemplate struct {
Cmd string
Err error
Cmd string
}
errs := []any(nil)

Expand Down
42 changes: 10 additions & 32 deletions core/arg_specs.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,39 +79,17 @@ func (s *ArgSpecs) AddBefore(name string, argSpec *ArgSpec) {
}

type ArgSpec struct {
// Name of the argument.
Name string

// Short description.
Short string

// Required defines whether the argument is required.
Required bool

// Default is the argument default value.
Default DefaultFunc

// EnumValues contains all possible values of an enum.
EnumValues []string

// AutoCompleteFunc is used to autocomplete possible values for a given argument.
Default DefaultFunc
AutoCompleteFunc AutoCompleteArgFunc

// ValidateFunc validates an argument.
ValidateFunc ArgSpecValidateFunc

// Positional defines whether the argument is a positional argument. NB: a positional argument is required.
Positional bool

// Only one argument of the same OneOfGroup could be specified
OneOfGroup string

// Deprecated is used to flag an argument as deprecated.
// Use the short field to indicate migration tips for users.
Deprecated bool

// CanLoadFile allow to use @ prefix to load a file as content
CanLoadFile bool
ValidateFunc ArgSpecValidateFunc
Name string
Short string
OneOfGroup string
EnumValues []string
Required bool
Positional bool
Deprecated bool
CanLoadFile bool
}

func (a *ArgSpec) Prefix() string {
Expand Down
6 changes: 2 additions & 4 deletions core/autocomplete.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,14 @@ type AutoCompleteNode struct {
Children map[string]*AutoCompleteNode
Command *Command
ArgSpec *ArgSpec
Name string
Type AutoCompleteNodeType

// Name of the current node. Useful for debugging.
Name string
}

type FlagSpec struct {
Name string
HasVariableValue bool
EnumValues []string
HasVariableValue bool
}

func (node *AutoCompleteNode) addFlags(flags []FlagSpec) {
Expand Down
2 changes: 1 addition & 1 deletion core/autocomplete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ func testAutocompleteGetCommands() *core.Commands {

type autoCompleteTestCase struct {
Suggestions core.AutocompleteSuggestions
WordToCompleteIndex int
Words []string
WordToCompleteIndex int
}

func runAutocompleteTest(ctx context.Context, tc *autoCompleteTestCase) func(*testing.T) {
Expand Down
68 changes: 15 additions & 53 deletions core/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,60 +18,22 @@ import (
)

type BootstrapConfig struct {
// Args to use for the command. Usually os.Args
Args []string

// A list of all available commands
Commands *Commands

// BuildInfo contains information about cli build
BuildInfo *BuildInfo

// Stdout stream to use. Usually os.Stdout
Stdout io.Writer

// Stderr stream to use. Usually os.Stderr
Stderr io.Writer

// Stdin stream to use. Usually os.Stdin
Stdin io.Reader

// If provided this client will be passed to all commands.
// If not a client will be automatically created by the CLI using Config, Env and flags see createClient().
Client *scw.Client

// DisableTelemetry, if set to true this will disable telemetry report no matter what the config send_telemetry is set to.
// This is useful when running test to avoid sending meaningless telemetries.
Stdin io.Reader
Platform platform.Platform
Ctx context.Context
Stdout io.Writer
Stderr io.Writer
Logger *Logger
Client *scw.Client
OverrideEnv map[string]string
OverrideExec OverrideExecFunc
BuildInfo *BuildInfo
HTTPClient *http.Client
Commands *Commands
Args []string
DisableTelemetry bool

// DisableAliases, if set to true this will disable aliases expanding
DisableAliases bool

// OverrideEnv overrides environment variables returned by core.ExtractEnv function.
// This is useful for tests as it allows overriding env without relying on global state.
OverrideEnv map[string]string

// OverrideExec allow to override exec.Cmd.Run method. In order for this to work
// your code must call le core.ExecCmd function to execute a given command.
// If this function is not defined the exec.Cmd.Run function will be called directly.
// This function is intended to be use for tests purposes.
OverrideExec OverrideExecFunc

// BaseContest is the base context that will be used across all function call from top to bottom.
Ctx context.Context

// Optional we use it if defined
Logger *Logger

// Default HTTPClient to use. If not provided it will use a basic http client with a simple retry policy
// This client will be used to create SDK client, account call, version checking and telemetry
HTTPClient *http.Client

// Enable beta functionalities
BetaMode bool

// The current platform, should probably be platform.Default
Platform platform.Platform
DisableAliases bool
BetaMode bool
}

// Bootstrap is the main entry point. It is directly called from main.
Expand Down
2 changes: 1 addition & 1 deletion core/cobra_utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ type testDate struct {
}

type testAcceptMultiPositionalArgsType struct {
NameIDs []string
Tag string
NameIDs []string
}

func testGetCommands() *core.Commands {
Expand Down
107 changes: 26 additions & 81 deletions core/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,87 +13,32 @@ import (

// Command represent a CLI command. From this higher level type we create Cobra command objects.
type Command struct {
// Namespace is the top level entry point of a command. (e.g scw instance)
Namespace string

// Resource is the 2nd command level. Resources are nested in a namespace. (e.g scw instance server)
Resource string

// Verb is the 3rd command level. Verbs are nested in a resource. (e.g scw instance server list)
Verb string

// Short documentation.
Short string

// Long documentation.
Long string

// AllowAnonymousClient defines whether the SDK client can run the command without be authenticated.
AllowAnonymousClient bool

// DisableTelemetry disable telemetry for the command.
DisableTelemetry bool

// DisableAfterChecks disable checks that run after the command to avoid superfluous message
DisableAfterChecks bool

// Hidden hides the command form usage and auto-complete.
Hidden bool

// ArgsType defines the type of argument for this command.
ArgsType reflect.Type

// ArgSpecs defines specifications for arguments.
ArgSpecs ArgSpecs

// AcceptMultiplePositionalArgs defines whether the command can accept multiple positional arguments.
// If enabled, positional argument is expected to be a list.
ArgsType reflect.Type
Run CommandRunner
Interceptor CommandInterceptor
PreValidateFunc CommandPreValidateFunc
View *View
ValidateFunc CommandValidateFunc
WaitFunc WaitFunc
WebURL string
WaitUsage string
Resource string
Namespace string
path string
Long string
Verb string
Short string
Aliases []string
Examples []*Example
ArgSpecs ArgSpecs
SeeAlsos []*SeeAlso
Groups []string
AcceptMultiplePositionalArgs bool

// View defines the View for this command.
// It is used to create the different options for the different Marshalers.
View *View

// Examples defines Examples for this command.
Examples []*Example

// SeeAlsos presents commands related to this command.
SeeAlsos []*SeeAlso

// PreValidateFunc allows to manipulate args before validation
PreValidateFunc CommandPreValidateFunc

// ValidateFunc validates a command.
// If nil, core.DefaultCommandValidateFunc is used by default.
ValidateFunc CommandValidateFunc

// Interceptor are middleware func that can intercept context and args before they are sent to Run
// You can combine multiple CommandInterceptor using AddInterceptors method.
Interceptor CommandInterceptor

// Run will be called to execute a command. It will receive a context and parsed argument.
// Non-nil values returned by this method will be printed out.
Run CommandRunner

// WaitFunc will be called if non-nil when the -w (--wait) flag is passed.
WaitFunc WaitFunc

// WebURL will be used as url to open when the --web flag is passed
// Can contain template of values in request, ex: "url/{{ .Zone }}/{{ .ResourceID }}"
WebURL string

// WaitUsage override the usage for the -w (--wait) flag
WaitUsage string

// Aliases contains a list of aliases for a command
Aliases []string
// cache command path
path string

// Groups contains a list of groups IDs
Groups []string
//
Deprecated bool
Hidden bool
DisableAfterChecks bool
DisableTelemetry bool
AllowAnonymousClient bool
Deprecated bool
}

// CommandPreValidateFunc allows to manipulate args before validation.
Expand Down Expand Up @@ -203,8 +148,8 @@ func (c *Command) MatchAlias(alias alias.Alias) bool {

// Commands represent a list of CLI commands, with a index to allow searching.
type Commands struct {
commands []*Command
commandIndex map[string]*Command
commands []*Command
}

func NewCommands(cmds ...*Command) *Commands {
Expand Down
33 changes: 15 additions & 18 deletions core/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,23 @@ import (

// Meta store globally available variables like sdk client or global Flags.
type Meta struct {
BinaryName string

ProfileFlag string
ConfigPathFlag string
Logger *Logger

BuildInfo *BuildInfo
Client *scw.Client
Commands *Commands
OverrideEnv map[string]string
OverrideExec OverrideExecFunc
CliConfig *cliConfig.Config
Platform platform.Platform

command *Command
stdout io.Writer
stderr io.Writer
stdin io.Reader
Platform platform.Platform
result interface{}
stdin io.Reader
stderr io.Writer
stdout io.Writer
BuildInfo *BuildInfo
httpClient *http.Client
OverrideEnv map[string]string
OverrideExec OverrideExecFunc
CliConfig *cliConfig.Config
Client *scw.Client
command *Command
Commands *Commands
Logger *Logger
BinaryName string
ProfileFlag string
ConfigPathFlag string
isClientFromBootstrapConfig bool
BetaMode bool
}
Expand Down
5 changes: 1 addition & 4 deletions core/human/marshal_func.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,11 +207,8 @@ func isMarshalable(t reflect.Type) bool {

// EnumMarshalSpec contains specs used by EnumMarshalFunc.
type EnumMarshalSpec struct {
// Attribute (mainly colors) to use.
Value string
Attribute color.Attribute

// Value is the value that will be printed for the given value.
Value string
}

type EnumMarshalSpecs map[interface{}]*EnumMarshalSpec
Expand Down
Loading
Loading