Skip to content

Commit 52d4447

Browse files
committed
feature: refactored flag initialization
1 parent 8f7695c commit 52d4447

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ func NewCmd(p *print.Printer) *cobra.Command {
4646
}
4747

4848
func configureFlags(cmd *cobra.Command) {
49+
globalflags.Configure(cmd.Flags())
4950
cmd.Flags().String("name", "", "the name of the security group. Must be <= 63 chars")
5051
cmd.Flags().String("description", "", "an optional description of the security group. Must be <= 127 chars")
5152
cmd.Flags().Bool("stateful", false, "create a stateful or a stateless security group")

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

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@ import (
66
"strings"
77

88
"github.com/spf13/cobra"
9+
"github.com/stackitcloud/stackit-cli/internal/pkg/args"
910
"github.com/stackitcloud/stackit-cli/internal/pkg/errors"
1011
"github.com/stackitcloud/stackit-cli/internal/pkg/examples"
1112
"github.com/stackitcloud/stackit-cli/internal/pkg/flags"
1213
"github.com/stackitcloud/stackit-cli/internal/pkg/globalflags"
1314
"github.com/stackitcloud/stackit-cli/internal/pkg/print"
1415
"github.com/stackitcloud/stackit-cli/internal/pkg/services/iaas/client"
16+
"github.com/stackitcloud/stackit-cli/internal/pkg/utils"
1517
"github.com/stackitcloud/stackit-sdk-go/services/iaas"
1618
)
1719

@@ -20,12 +22,14 @@ type inputModel struct {
2022
Id string
2123
}
2224

25+
const argNameGroupId = "groupId"
26+
2327
func NewCmd(p *print.Printer) *cobra.Command {
2428
cmd := &cobra.Command{
2529
Use: "delete",
2630
Short: "delete a security group",
2731
Long: "delete a security group by its internal id",
28-
Args: cobra.ExactArgs(1),
32+
Args: args.SingleArg(argNameGroupId, utils.ValidateUUID),
2933
Example: examples.Build(
3034
examples.NewExample(`delete a named group`, `$ stackit beta security-group delete 43ad419a-c68b-4911-87cd-e05752ac1e31`),
3135
),
@@ -80,9 +84,18 @@ func parseInput(p *print.Printer, cmd *cobra.Command, args []string) (*inputMode
8084
if globalFlags.ProjectId == "" {
8185
return nil, &errors.ProjectIdError{}
8286
}
87+
if err := cmd.ValidateArgs(args); err != nil {
88+
return nil, &errors.ArgValidationError{
89+
Arg: argNameGroupId,
90+
Details: fmt.Sprintf("arg validation failed: %v", err),
91+
}
92+
}
8393

8494
if len(args) != 1 {
85-
return nil,&errors.ArgValidationError{}
95+
return nil, &errors.ArgValidationError{
96+
Arg: argNameGroupId,
97+
Details: "wrong number of arguments",
98+
}
8699
}
87100

88101
name := flags.FlagToStringValue(p, cmd, "name")

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ func NewCmd(p *print.Printer) *cobra.Command {
4545
}
4646

4747
func configureFlags(cmd *cobra.Command) {
48+
globalflags.Configure(cmd.Flags())
4849
cmd.Flags().String("labels", "", "a list of labels in the form <key>=<value>")
4950
}
5051

0 commit comments

Comments
 (0)