Skip to content

Commit 3ad022a

Browse files
committed
feature: fix linter warnings
1 parent 45d013c commit 3ad022a

File tree

9 files changed

+37
-42
lines changed

9 files changed

+37
-42
lines changed

internal/cmd/beta/security-group/create/create.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func NewCmd(p *print.Printer) *cobra.Command {
4343
examples.NewExample(`create a named group`, `$ stackit beta security-group create --name my-new-group`),
4444
examples.NewExample(`create a named group with labels`, `$ stackit beta security-group create --name my-new-group --labels label1=value1,label2=value2`),
4545
),
46-
RunE: func(cmd *cobra.Command, args []string) error {
46+
RunE: func(cmd *cobra.Command, _ []string) error {
4747
ctx := context.Background()
4848
model, err := parseInput(p, cmd)
4949
if err != nil {
@@ -114,7 +114,6 @@ func parseInput(p *print.Printer, cmd *cobra.Command) (*inputModel, error) {
114114
}
115115
}
116116
labels[parts[0]] = parts[1]
117-
118117
}
119118
description := flags.FlagToStringValue(p, cmd, descriptionFlag)
120119

@@ -153,7 +152,6 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APICli
153152
request = request.CreateSecurityGroupPayload(*payload)
154153

155154
return request
156-
157155
}
158156

159157
func outputResult(p *print.Printer, model *inputModel, resp *iaas.SecurityGroup) error {

internal/cmd/beta/security-group/delete/delete.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,19 +71,19 @@ func NewCmd(p *print.Printer) *cobra.Command {
7171
return cmd
7272
}
7373

74-
func parseInput(p *print.Printer, cmd *cobra.Command, args []string) (*inputModel, error) {
74+
func parseInput(p *print.Printer, cmd *cobra.Command, cliArgs []string) (*inputModel, error) {
7575
globalFlags := globalflags.Parse(p, cmd)
7676
if globalFlags.ProjectId == "" {
7777
return nil, &errors.ProjectIdError{}
7878
}
79-
if err := cmd.ValidateArgs(args); err != nil {
79+
if err := cmd.ValidateArgs(cliArgs); err != nil {
8080
return nil, &errors.ArgValidationError{
8181
Arg: argNameGroupId,
8282
Details: fmt.Sprintf("arg validation failed: %v", err),
8383
}
8484
}
8585

86-
if len(args) != 1 {
86+
if len(cliArgs) != 1 {
8787
return nil, &errors.ArgValidationError{
8888
Arg: argNameGroupId,
8989
Details: "wrong number of arguments",
@@ -108,7 +108,6 @@ func parseInput(p *print.Printer, cmd *cobra.Command, args []string) (*inputMode
108108
}
109109
}
110110
labels[parts[0]] = parts[1]
111-
112111
}
113112
description := flags.FlagToStringValue(p, cmd, "description")
114113
if len(description) >= 128 {
@@ -119,7 +118,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, args []string) (*inputMode
119118
}
120119
model := inputModel{
121120
GlobalFlagModel: globalFlags,
122-
Id: args[0],
121+
Id: cliArgs[0],
123122
}
124123

125124
if p.IsVerbosityDebug() {

internal/cmd/beta/security-group/delete/delete_test.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -84,28 +84,28 @@ func TestParseInput(t *testing.T) {
8484
},
8585
{
8686
description: "no arguments",
87-
flagValues: fixtureFlagValues(),
88-
args: nil,
89-
isValid: false,
87+
flagValues: fixtureFlagValues(),
88+
args: nil,
89+
isValid: false,
9090
},
9191
{
9292
description: "multiple arguments",
93-
flagValues: fixtureFlagValues(),
94-
args: []string{"foo","bar"},
95-
isValid: false,
93+
flagValues: fixtureFlagValues(),
94+
args: []string{"foo", "bar"},
95+
isValid: false,
9696
},
9797
{
9898
description: "invalid group id",
99-
flagValues: fixtureFlagValues(),
100-
args: []string{"foo"},
101-
isValid: false,
99+
flagValues: fixtureFlagValues(),
100+
args: []string{"foo"},
101+
isValid: false,
102102
},
103103
}
104104

105105
for _, tt := range tests {
106106
t.Run(tt.description, func(t *testing.T) {
107107
p := print.NewPrinter()
108-
cmd:=NewCmd(p)
108+
cmd := NewCmd(p)
109109
err := globalflags.Configure(cmd.Flags())
110110
if err != nil {
111111
t.Fatalf("configure global flags: %v", err)

internal/cmd/beta/security-group/describe/describe.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,15 +71,14 @@ func NewCmd(p *print.Printer) *cobra.Command {
7171
func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APIClient) iaas.ApiGetSecurityGroupRequest {
7272
request := apiClient.GetSecurityGroup(ctx, model.ProjectId, model.SecurityGroupId)
7373
return request
74-
7574
}
7675

77-
func parseInput(p *print.Printer, cmd *cobra.Command, args []string) (*inputModel, error) {
76+
func parseInput(p *print.Printer, cmd *cobra.Command, cliArgs []string) (*inputModel, error) {
7877
globalFlags := globalflags.Parse(p, cmd)
7978
if globalFlags.ProjectId == "" {
8079
return nil, &errors.ProjectIdError{}
8180
}
82-
if err := cmd.ValidateArgs(args); err != nil {
81+
if err := cmd.ValidateArgs(cliArgs); err != nil {
8382
return nil, &errors.ArgValidationError{
8483
Arg: argNameGroupId,
8584
Details: fmt.Sprintf("argument validation failed: %v", err),
@@ -88,7 +87,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, args []string) (*inputMode
8887

8988
model := inputModel{
9089
GlobalFlagModel: globalFlags,
91-
SecurityGroupId: args[0],
90+
SecurityGroupId: cliArgs[0],
9291
}
9392

9493
if p.IsVerbosityDebug() {

internal/cmd/beta/security-group/describe/describe_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,37 +65,37 @@ func TestParseInput(t *testing.T) {
6565
description: "base",
6666
flagValues: fixtureFlagValues(),
6767
expectedModel: fixtureInputModel(),
68-
args: testSecurityGroupId,
68+
args: testSecurityGroupId,
6969
isValid: true,
7070
},
7171
{
7272
description: "no values",
7373
flagValues: map[string]string{},
74-
args: testSecurityGroupId,
74+
args: testSecurityGroupId,
7575
isValid: false,
7676
},
7777
{
7878
description: "project id missing",
7979
flagValues: fixtureFlagValues(func(flagValues map[string]string) {
8080
delete(flagValues, projectIdFlag)
8181
}),
82-
args: testSecurityGroupId,
82+
args: testSecurityGroupId,
8383
isValid: false,
8484
},
8585
{
8686
description: "project id invalid 1",
8787
flagValues: fixtureFlagValues(func(flagValues map[string]string) {
8888
flagValues[projectIdFlag] = ""
8989
}),
90-
args: testSecurityGroupId,
90+
args: testSecurityGroupId,
9191
isValid: false,
9292
},
9393
{
9494
description: "project id invalid 2",
9595
flagValues: fixtureFlagValues(func(flagValues map[string]string) {
9696
flagValues[projectIdFlag] = "invalid-uuid"
9797
}),
98-
args: testSecurityGroupId,
98+
args: testSecurityGroupId,
9999
isValid: false,
100100
},
101101
{

internal/cmd/beta/security-group/list/list.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func NewCmd(p *print.Printer) *cobra.Command {
3939
examples.NewExample(`list all groups`, `$ stackit beta security-group list`),
4040
examples.NewExample(`list groups with labels`, `$ stackit beta security-group list --labels label1=value1,label2=value2`),
4141
),
42-
RunE: func(cmd *cobra.Command, args []string) error {
42+
RunE: func(cmd *cobra.Command, _ []string) error {
4343
ctx := context.Background()
4444
model, err := parseInput(p, cmd)
4545
if err != nil {
@@ -67,7 +67,9 @@ func NewCmd(p *print.Printer) *cobra.Command {
6767
if items := response.GetItems(); items == nil || len(*items) == 0 {
6868
p.Info("no security groups found for %q", projectLabel)
6969
} else {
70-
outputResult(p, model.OutputFormat, *items)
70+
if err := outputResult(p, model.OutputFormat, *items); err != nil {
71+
return fmt.Errorf("output security groups: %w", err)
72+
}
7173
}
7274

7375
return nil
@@ -112,7 +114,6 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APICli
112114
}
113115

114116
return request
115-
116117
}
117118
func outputResult(p *print.Printer, outputFormat string, items []iaas.SecurityGroup) error {
118119
switch outputFormat {
@@ -136,7 +137,7 @@ func outputResult(p *print.Printer, outputFormat string, items []iaas.SecurityGr
136137
table := tables.NewTable()
137138
table.SetHeader("ID", "NAME", labelSelectorFlag, "STATEFUL")
138139
for _, item := range items {
139-
table.AddRow(ptrString(item.Id), ptrString(item.Name), concatLabels(item.Labels), ptrString(item.Stateful))
140+
table.AddRow(ptrString(item.Id), ptrString(item.Name), concatLabels(*item.Labels), ptrString(item.Stateful))
140141
}
141142
err := table.Display(p)
142143
if err != nil {
@@ -154,12 +155,12 @@ func ptrString[T any](t *T) string {
154155
return ""
155156
}
156157

157-
func concatLabels(item *map[string]any) string {
158+
func concatLabels(item map[string]any) string {
158159
if item == nil {
159160
return ""
160161
}
161162
var builder strings.Builder
162-
for k, v := range *item {
163+
for k, v := range item {
163164
builder.WriteString(fmt.Sprintf("%s=%v ", k, v))
164165
}
165166
return builder.String()

internal/cmd/beta/security-group/list/list_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,12 @@ var (
2323
testClient = &iaas.APIClient{}
2424
testProjectId = uuid.NewString()
2525
testLabels = "fooKey=fooValue,barKey=barValue,bazKey=bazValue"
26-
testStateful = true
2726
)
2827

2928
func fixtureFlagValues(mods ...func(flagValues map[string]string)) map[string]string {
3029
flagValues := map[string]string{
31-
projectIdFlag: testProjectId,
32-
labelSelectorFlag: testLabels,
30+
projectIdFlag: testProjectId,
31+
labelSelectorFlag: testLabels,
3332
}
3433
for _, mod := range mods {
3534
mod(flagValues)

internal/cmd/beta/security-group/update/update.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,13 @@ func configureFlags(cmd *cobra.Command) {
8080
cmd.Flags().StringSlice("labels", nil, "Labels are key-value string pairs which can be attached to a network-interface. E.g. '--labels key1=value1,key2=value2,...'")
8181
}
8282

83-
func parseInput(p *print.Printer, cmd *cobra.Command, args []string) (*inputModel, error) {
83+
func parseInput(p *print.Printer, cmd *cobra.Command, cliArgs []string) (*inputModel, error) {
8484
globalFlags := globalflags.Parse(p, cmd)
8585
if globalFlags.ProjectId == "" {
8686
return nil, &errors.ProjectIdError{}
8787
}
8888

89-
if err := cmd.ValidateArgs(args); err != nil {
89+
if err := cmd.ValidateArgs(cliArgs); err != nil {
9090
return nil, &errors.ArgValidationError{
9191
Arg: argNameGroupId,
9292
Details: fmt.Sprintf("argument validation failed: %v", err),
@@ -96,13 +96,13 @@ func parseInput(p *print.Printer, cmd *cobra.Command, args []string) (*inputMode
9696
model := inputModel{
9797
GlobalFlagModel: globalFlags,
9898
}
99-
if len(args) != 1 {
99+
if len(cliArgs) != 1 {
100100
return nil, &errors.ArgValidationError{
101101
Arg: argNameGroupId,
102102
Details: "wrong number of arguments",
103103
}
104104
}
105-
model.SecurityGroupId = args[0]
105+
model.SecurityGroupId = cliArgs[0]
106106

107107
if cmd.Flags().Lookup("name").Changed {
108108
name := flags.FlagToStringValue(p, cmd, "name")
@@ -149,5 +149,4 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APICli
149149
request = request.UpdateSecurityGroupPayload(*payload)
150150

151151
return request
152-
153152
}

internal/cmd/beta/security-group/update/update_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,8 @@ func TestParseInput(t *testing.T) {
212212
if err := globalflags.Configure(cmd.Flags()); err != nil {
213213
t.Errorf("cannot configure global flags: %v", err)
214214
}
215-
for flag, value := range tt.flagValues {
216215

216+
for flag, value := range tt.flagValues {
217217
if err := cmd.Flags().Set(flag, value); err != nil {
218218
if !tt.isValid {
219219
return

0 commit comments

Comments
 (0)