From 922bce076ebe04a9fad60f954c6b872fa207c9d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Palet?= Date: Wed, 22 Nov 2023 16:20:06 +0000 Subject: [PATCH 1/2] Implement flag in list commands --- internal/cmd/dns/record-set/list/list.go | 15 ++++++++++ internal/cmd/dns/zone/list/list.go | 14 +++++++++ .../cmd/postgresql/credential/list/list.go | 14 +++++++++ internal/cmd/postgresql/instance/list/list.go | 25 +++++++++++++++- internal/cmd/postgresql/offering/list/list.go | 29 ++++++++++++++++++- internal/cmd/ske/cluster/list/list.go | 24 +++++++++++++-- 6 files changed, 117 insertions(+), 4 deletions(-) diff --git a/internal/cmd/dns/record-set/list/list.go b/internal/cmd/dns/record-set/list/list.go index fd23091f..e38939be 100644 --- a/internal/cmd/dns/record-set/list/list.go +++ b/internal/cmd/dns/record-set/list/list.go @@ -22,6 +22,7 @@ const ( nameLikeFlag = "name-like" activeFlag = "is-active" orderByNameFlag = "order-by-name" + limitFlag = "limit" ) type flagModel struct { @@ -30,6 +31,7 @@ type flagModel struct { NameLike *string Active *bool OrderByName *string + Limit *int64 } func NewCmd() *cobra.Command { @@ -63,6 +65,11 @@ func NewCmd() *cobra.Command { return nil } + // Truncate output + if model.Limit != nil && len(recordSets) > int(*model.Limit) { + recordSets = recordSets[:*model.Limit] + } + // Show output as table table := tables.NewTable() table.SetHeader("ID", "Name", "Type", "State") @@ -75,6 +82,7 @@ func NewCmd() *cobra.Command { return nil }, } + configureFlags(cmd) return cmd } @@ -87,6 +95,7 @@ func configureFlags(cmd *cobra.Command) { cmd.Flags().String(nameLikeFlag, "", "Filter by name") cmd.Flags().Var(flags.EnumBoolFlag(), activeFlag, fmt.Sprintf("Filter by active status, one of %q", activeFlagOptions)) cmd.Flags().Var(flags.EnumFlag(true, orderByNameFlagOptions...), orderByNameFlag, fmt.Sprintf("Order by name, one of %q", orderByNameFlagOptions)) + cmd.Flags().Int64(limitFlag, 0, "Maximum number of entries to list") err := utils.MarkFlagsRequired(cmd, zoneIdFlag) cobra.CheckErr(err) @@ -98,12 +107,18 @@ func parseFlags(cmd *cobra.Command) (*flagModel, error) { return nil, fmt.Errorf("project ID not set") } + limit := utils.FlagToInt64Pointer(cmd, limitFlag) + if limit != nil && *limit < 1 { + return nil, fmt.Errorf("limit must be greater than 0") + } + return &flagModel{ ProjectId: projectId, ZoneId: utils.FlagToStringValue(cmd, zoneIdFlag), NameLike: utils.FlagToStringPointer(cmd, nameLikeFlag), Active: utils.FlagToBoolPointer(cmd, activeFlag), OrderByName: utils.FlagToStringPointer(cmd, orderByNameFlag), + Limit: utils.FlagToInt64Pointer(cmd, limitFlag), }, nil } diff --git a/internal/cmd/dns/zone/list/list.go b/internal/cmd/dns/zone/list/list.go index adafbde7..adbac624 100644 --- a/internal/cmd/dns/zone/list/list.go +++ b/internal/cmd/dns/zone/list/list.go @@ -21,6 +21,7 @@ const ( nameLikeFlag = "name-like" activeFlag = "is-active" orderByNameFlag = "order-by-name" + limitFlag = "limit" ) type flagModel struct { @@ -28,6 +29,7 @@ type flagModel struct { NameLike *string Active *bool OrderByName *string + Limit *int64 } func NewCmd() *cobra.Command { @@ -61,6 +63,11 @@ func NewCmd() *cobra.Command { return nil } + // Truncate output + if model.Limit != nil && len(zones) > int(*model.Limit) { + zones = zones[:*model.Limit] + } + // Show output as table table := tables.NewTable() table.SetHeader("ID", "NAME", "DNS_NAME", "STATE") @@ -84,6 +91,7 @@ func configureFlags(cmd *cobra.Command) { cmd.Flags().String(nameLikeFlag, "", "Filter by name") cmd.Flags().Var(flags.EnumBoolFlag(), activeFlag, fmt.Sprintf("Filter by active status, one of %q", activeFlagOptions)) cmd.Flags().Var(flags.EnumFlag(true, orderByNameFlagOptions...), orderByNameFlag, fmt.Sprintf("Order by name, one of %q", orderByNameFlagOptions)) + cmd.Flags().Int64(limitFlag, 0, "Maximum number of entries to list") } func parseFlags(cmd *cobra.Command) (*flagModel, error) { @@ -92,11 +100,17 @@ func parseFlags(cmd *cobra.Command) (*flagModel, error) { return nil, fmt.Errorf("project ID not set") } + limit := utils.FlagToInt64Pointer(cmd, limitFlag) + if limit != nil && *limit < 1 { + return nil, fmt.Errorf("limit must be greater than 0") + } + return &flagModel{ ProjectId: projectId, NameLike: utils.FlagToStringPointer(cmd, nameLikeFlag), Active: utils.FlagToBoolPointer(cmd, activeFlag), OrderByName: utils.FlagToStringPointer(cmd, orderByNameFlag), + Limit: limit, }, nil } diff --git a/internal/cmd/postgresql/credential/list/list.go b/internal/cmd/postgresql/credential/list/list.go index 830719c3..435b15f3 100644 --- a/internal/cmd/postgresql/credential/list/list.go +++ b/internal/cmd/postgresql/credential/list/list.go @@ -18,11 +18,13 @@ import ( const ( projectIdFlag = "project-id" instanceIdFlag = "instance-id" + limitFlag = "limit" ) type flagModel struct { ProjectId string InstanceId string + Limit *int64 } func NewCmd() *cobra.Command { @@ -56,6 +58,11 @@ func NewCmd() *cobra.Command { return nil } + // Truncate output + if model.Limit != nil && len(credentials) > int(*model.Limit) { + credentials = credentials[:*model.Limit] + } + // Show output as table table := tables.NewTable() table.SetHeader("ID") @@ -74,6 +81,7 @@ func NewCmd() *cobra.Command { func configureFlags(cmd *cobra.Command) { cmd.Flags().Var(flags.UUIDFlag(), instanceIdFlag, "Instance ID") + cmd.Flags().Int64(limitFlag, 0, "Maximum number of entries to list") err := utils.MarkFlagsRequired(cmd, instanceIdFlag) cobra.CheckErr(err) @@ -85,9 +93,15 @@ func parseFlags(cmd *cobra.Command) (*flagModel, error) { return nil, fmt.Errorf("project ID not set") } + limit := utils.FlagToInt64Pointer(cmd, limitFlag) + if limit != nil && *limit < 1 { + return nil, fmt.Errorf("limit must be greater than 0") + } + return &flagModel{ ProjectId: projectId, InstanceId: utils.FlagToStringValue(cmd, instanceIdFlag), + Limit: limit, }, nil } diff --git a/internal/cmd/postgresql/instance/list/list.go b/internal/cmd/postgresql/instance/list/list.go index 91d3a6a6..a7eb42fd 100644 --- a/internal/cmd/postgresql/instance/list/list.go +++ b/internal/cmd/postgresql/instance/list/list.go @@ -7,14 +7,20 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/config" "github.com/stackitcloud/stackit-cli/internal/pkg/services/postgresql/client" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" + "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/spf13/cobra" "github.com/spf13/viper" "github.com/stackitcloud/stackit-sdk-go/services/postgresql" ) +const ( + limitFlag = "limit" +) + type flagModel struct { ProjectId string + Limit *int64 } func NewCmd() *cobra.Command { @@ -48,6 +54,11 @@ func NewCmd() *cobra.Command { return nil } + // Truncate output + if model.Limit != nil && len(instances) > int(*model.Limit) { + instances = instances[:*model.Limit] + } + // Show output as table table := tables.NewTable() table.SetHeader("ID", "NAME", "LAST_OPERATION.TYPE", "LAST_OPERATION.STATE") @@ -60,17 +71,29 @@ func NewCmd() *cobra.Command { return nil }, } + + configureFlags(cmd) return cmd } -func parseFlags(_ *cobra.Command) (*flagModel, error) { +func configureFlags(cmd *cobra.Command) { + cmd.Flags().Int64(limitFlag, 0, "Maximum number of entries to list") +} + +func parseFlags(cmd *cobra.Command) (*flagModel, error) { projectId := viper.GetString(config.ProjectIdKey) if projectId == "" { return nil, fmt.Errorf("project ID not set") } + limit := utils.FlagToInt64Pointer(cmd, limitFlag) + if limit != nil && *limit < 1 { + return nil, fmt.Errorf("limit must be greater than 0") + } + return &flagModel{ ProjectId: projectId, + Limit: utils.FlagToInt64Pointer(cmd, limitFlag), }, nil } diff --git a/internal/cmd/postgresql/offering/list/list.go b/internal/cmd/postgresql/offering/list/list.go index b6bfcb70..cbcb84e1 100644 --- a/internal/cmd/postgresql/offering/list/list.go +++ b/internal/cmd/postgresql/offering/list/list.go @@ -7,14 +7,20 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/config" "github.com/stackitcloud/stackit-cli/internal/pkg/services/postgresql/client" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" + "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/spf13/cobra" "github.com/spf13/viper" "github.com/stackitcloud/stackit-sdk-go/services/postgresql" ) +const ( + limitFlag = "limit" +) + type flagModel struct { ProjectId string + Limit *int64 } func NewCmd() *cobra.Command { @@ -43,6 +49,15 @@ func NewCmd() *cobra.Command { return fmt.Errorf("get PostgreSQL service offerings: %w", err) } offerings := *resp.Offerings + if len(offerings) == 0 { + cmd.Printf("No offerings found for project with ID %s\n", model.ProjectId) + return nil + } + + // Truncate output + if model.Limit != nil && len(offerings) > int(*model.Limit) { + offerings = offerings[:*model.Limit] + } // Show output as table table := tables.NewTable() @@ -61,17 +76,29 @@ func NewCmd() *cobra.Command { return nil }, } + + configureFlags(cmd) return cmd } -func parseFlags(_ *cobra.Command) (*flagModel, error) { +func configureFlags(cmd *cobra.Command) { + cmd.Flags().Int64(limitFlag, 0, "Maximum number of entries to list") +} + +func parseFlags(cmd *cobra.Command) (*flagModel, error) { projectId := viper.GetString(config.ProjectIdKey) if projectId == "" { return nil, fmt.Errorf("project ID not set") } + limit := utils.FlagToInt64Pointer(cmd, limitFlag) + if limit != nil && *limit < 1 { + return nil, fmt.Errorf("limit must be greater than 0") + } + return &flagModel{ ProjectId: projectId, + Limit: limit, }, nil } diff --git a/internal/cmd/ske/cluster/list/list.go b/internal/cmd/ske/cluster/list/list.go index 5a323121..7c006b74 100644 --- a/internal/cmd/ske/cluster/list/list.go +++ b/internal/cmd/ske/cluster/list/list.go @@ -7,6 +7,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/config" "github.com/stackitcloud/stackit-cli/internal/pkg/services/ske/client" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" + "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/spf13/cobra" "github.com/spf13/viper" @@ -15,10 +16,12 @@ import ( const ( projectIdFlag = "project-id" + limitFlag = "limit" ) type flagModel struct { ProjectId string + Limit *int64 } func NewCmd() *cobra.Command { @@ -29,7 +32,7 @@ func NewCmd() *cobra.Command { Example: `$ stackit ske cluster list --project-id xxx`, RunE: func(cmd *cobra.Command, args []string) error { ctx := context.Background() - model, err := parseFlags() + model, err := parseFlags(cmd) if err != nil { return err } @@ -52,6 +55,11 @@ func NewCmd() *cobra.Command { return nil } + // Truncate output + if model.Limit != nil && len(clusters) > int(*model.Limit) { + clusters = clusters[:*model.Limit] + } + // Show output as table table := tables.NewTable() table.SetHeader("NAME", "STATE") @@ -64,17 +72,29 @@ func NewCmd() *cobra.Command { return nil }, } + + configureFlags(cmd) return cmd } -func parseFlags() (*flagModel, error) { +func configureFlags(cmd *cobra.Command) { + cmd.Flags().Int64(limitFlag, 0, "Maximum number of entries to list") +} + +func parseFlags(cmd *cobra.Command) (*flagModel, error) { projectId := viper.GetString(config.ProjectIdKey) if projectId == "" { return nil, fmt.Errorf("project ID not set") } + limit := utils.FlagToInt64Pointer(cmd, limitFlag) + if limit != nil && *limit < 1 { + return nil, fmt.Errorf("limit must be greater than 0") + } + return &flagModel{ ProjectId: projectId, + Limit: utils.FlagToInt64Pointer(cmd, limitFlag), }, nil } From 3fc35fd94dc18708f4336eacf9dc1beef5187d5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Palet?= Date: Wed, 22 Nov 2023 16:20:17 +0000 Subject: [PATCH 2/2] Extend tests --- internal/cmd/dns/record-set/list/list_test.go | 16 ++++++++++++++ internal/cmd/dns/zone/list/list_test.go | 16 ++++++++++++++ .../postgresql/credential/list/list_test.go | 17 +++++++++++++++ .../cmd/postgresql/instance/list/list_test.go | 19 +++++++++++++++++ .../cmd/postgresql/offering/list/list_test.go | 19 +++++++++++++++++ internal/cmd/ske/cluster/list/list_test.go | 21 ++++++++++++++++++- 6 files changed, 107 insertions(+), 1 deletion(-) diff --git a/internal/cmd/dns/record-set/list/list_test.go b/internal/cmd/dns/record-set/list/list_test.go index 96b4e0a1..df92ba7a 100644 --- a/internal/cmd/dns/record-set/list/list_test.go +++ b/internal/cmd/dns/record-set/list/list_test.go @@ -29,6 +29,7 @@ func fixtureFlagValues(mods ...func(flagValues map[string]string)) map[string]st nameLikeFlag: "some-pattern", activeFlag: "true", orderByNameFlag: "asc", + limitFlag: "10", } for _, mod := range mods { mod(flagValues) @@ -43,6 +44,7 @@ func fixtureFlagModel(mods ...func(model *flagModel)) *flagModel { NameLike: utils.Ptr("some-pattern"), Active: utils.Ptr(true), OrderByName: utils.Ptr("asc"), + Limit: utils.Ptr(int64(10)), } for _, mod := range mods { mod(model) @@ -170,6 +172,20 @@ func TestParseFlags(t *testing.T) { }), isValid: false, }, + { + description: "limit invalid", + flagValues: fixtureFlagValues(func(flagValues map[string]string) { + flagValues[limitFlag] = "invalid" + }), + isValid: false, + }, + { + description: "limit invalid 2", + flagValues: fixtureFlagValues(func(flagValues map[string]string) { + flagValues[limitFlag] = "0" + }), + isValid: false, + }, } for _, tt := range tests { diff --git a/internal/cmd/dns/zone/list/list_test.go b/internal/cmd/dns/zone/list/list_test.go index 8992c872..3dcbd19e 100644 --- a/internal/cmd/dns/zone/list/list_test.go +++ b/internal/cmd/dns/zone/list/list_test.go @@ -27,6 +27,7 @@ func fixtureFlagValues(mods ...func(flagValues map[string]string)) map[string]st nameLikeFlag: "some-pattern", activeFlag: "true", orderByNameFlag: "asc", + limitFlag: "10", } for _, mod := range mods { mod(flagValues) @@ -40,6 +41,7 @@ func fixtureFlagModel(mods ...func(model *flagModel)) *flagModel { NameLike: utils.Ptr("some-pattern"), Active: utils.Ptr(true), OrderByName: utils.Ptr("asc"), + Limit: utils.Ptr(int64(10)), } for _, mod := range mods { mod(model) @@ -165,6 +167,20 @@ func TestParseFlags(t *testing.T) { }), isValid: false, }, + { + description: "limit invalid", + flagValues: fixtureFlagValues(func(flagValues map[string]string) { + flagValues[limitFlag] = "invalid" + }), + isValid: false, + }, + { + description: "limit invalid 2", + flagValues: fixtureFlagValues(func(flagValues map[string]string) { + flagValues[limitFlag] = "0" + }), + isValid: false, + }, } for _, tt := range tests { diff --git a/internal/cmd/postgresql/credential/list/list_test.go b/internal/cmd/postgresql/credential/list/list_test.go index 867725ba..db693dc1 100644 --- a/internal/cmd/postgresql/credential/list/list_test.go +++ b/internal/cmd/postgresql/credential/list/list_test.go @@ -6,6 +6,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/config" "github.com/stackitcloud/stackit-cli/internal/pkg/testutils" + "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" @@ -25,6 +26,7 @@ func fixtureFlagValues(mods ...func(flagValues map[string]string)) map[string]st flagValues := map[string]string{ projectIdFlag: testProjectId, instanceIdFlag: testInstanceId, + limitFlag: "10", } for _, mod := range mods { mod(flagValues) @@ -36,6 +38,7 @@ func fixtureFlagModel(mods ...func(model *flagModel)) *flagModel { model := &flagModel{ ProjectId: testProjectId, InstanceId: testInstanceId, + Limit: utils.Ptr(int64(10)), } for _, mod := range mods { mod(model) @@ -111,6 +114,20 @@ func TestParseFlags(t *testing.T) { }), isValid: false, }, + { + description: "limit invalid", + flagValues: fixtureFlagValues(func(flagValues map[string]string) { + flagValues[limitFlag] = "invalid" + }), + isValid: false, + }, + { + description: "limit invalid 2", + flagValues: fixtureFlagValues(func(flagValues map[string]string) { + flagValues[limitFlag] = "0" + }), + isValid: false, + }, } for _, tt := range tests { diff --git a/internal/cmd/postgresql/instance/list/list_test.go b/internal/cmd/postgresql/instance/list/list_test.go index bc9bf61c..6d34c311 100644 --- a/internal/cmd/postgresql/instance/list/list_test.go +++ b/internal/cmd/postgresql/instance/list/list_test.go @@ -6,6 +6,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/config" "github.com/stackitcloud/stackit-cli/internal/pkg/testutils" + "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" @@ -27,6 +28,7 @@ var testProjectId = uuid.NewString() func fixtureFlagValues(mods ...func(flagValues map[string]string)) map[string]string { flagValues := map[string]string{ projectIdFlag: testProjectId, + limitFlag: "10", } for _, mod := range mods { mod(flagValues) @@ -37,6 +39,7 @@ func fixtureFlagValues(mods ...func(flagValues map[string]string)) map[string]st func fixtureFlagModel(mods ...func(model *flagModel)) *flagModel { model := &flagModel{ ProjectId: testProjectId, + Limit: utils.Ptr(int64(10)), } for _, mod := range mods { mod(model) @@ -91,6 +94,20 @@ func TestParseFlags(t *testing.T) { }), isValid: false, }, + { + description: "limit invalid", + flagValues: fixtureFlagValues(func(flagValues map[string]string) { + flagValues[limitFlag] = "invalid" + }), + isValid: false, + }, + { + description: "limit invalid 2", + flagValues: fixtureFlagValues(func(flagValues map[string]string) { + flagValues[limitFlag] = "0" + }), + isValid: false, + }, } for _, tt := range tests { @@ -103,6 +120,8 @@ func TestParseFlags(t *testing.T) { t.Fatalf("configure global flag --%s: %v", projectIdFlag, err) } + configureFlags(cmd) + for flag, value := range tt.flagValues { err := cmd.Flags().Set(flag, value) if err != nil { diff --git a/internal/cmd/postgresql/offering/list/list_test.go b/internal/cmd/postgresql/offering/list/list_test.go index dec9e1a2..ec8f55ed 100644 --- a/internal/cmd/postgresql/offering/list/list_test.go +++ b/internal/cmd/postgresql/offering/list/list_test.go @@ -6,6 +6,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/config" "github.com/stackitcloud/stackit-cli/internal/pkg/testutils" + "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" @@ -27,6 +28,7 @@ var testProjectId = uuid.NewString() func fixtureFlagValues(mods ...func(flagValues map[string]string)) map[string]string { flagValues := map[string]string{ projectIdFlag: testProjectId, + limitFlag: "10", } for _, mod := range mods { mod(flagValues) @@ -37,6 +39,7 @@ func fixtureFlagValues(mods ...func(flagValues map[string]string)) map[string]st func fixtureFlagModel(mods ...func(model *flagModel)) *flagModel { model := &flagModel{ ProjectId: testProjectId, + Limit: utils.Ptr(int64(10)), } for _, mod := range mods { mod(model) @@ -91,6 +94,20 @@ func TestParseFlags(t *testing.T) { }), isValid: false, }, + { + description: "limit invalid", + flagValues: fixtureFlagValues(func(flagValues map[string]string) { + flagValues[limitFlag] = "invalid" + }), + isValid: false, + }, + { + description: "limit invalid 2", + flagValues: fixtureFlagValues(func(flagValues map[string]string) { + flagValues[limitFlag] = "0" + }), + isValid: false, + }, } for _, tt := range tests { @@ -103,6 +120,8 @@ func TestParseFlags(t *testing.T) { t.Fatalf("configure global flag --%s: %v", projectIdFlag, err) } + configureFlags(cmd) + for flag, value := range tt.flagValues { err := cmd.Flags().Set(flag, value) if err != nil { diff --git a/internal/cmd/ske/cluster/list/list_test.go b/internal/cmd/ske/cluster/list/list_test.go index f3a6e2bb..c3a181a0 100644 --- a/internal/cmd/ske/cluster/list/list_test.go +++ b/internal/cmd/ske/cluster/list/list_test.go @@ -6,6 +6,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/config" "github.com/stackitcloud/stackit-cli/internal/pkg/testutils" + "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" @@ -23,6 +24,7 @@ var testProjectId = uuid.NewString() func fixtureFlagValues(mods ...func(flagValues map[string]string)) map[string]string { flagValues := map[string]string{ projectIdFlag: testProjectId, + limitFlag: "10", } for _, mod := range mods { mod(flagValues) @@ -33,6 +35,7 @@ func fixtureFlagValues(mods ...func(flagValues map[string]string)) map[string]st func fixtureFlagModel(mods ...func(model *flagModel)) *flagModel { model := &flagModel{ ProjectId: testProjectId, + Limit: utils.Ptr(int64(10)), } for _, mod := range mods { mod(model) @@ -87,6 +90,20 @@ func TestParseFlags(t *testing.T) { }), isValid: false, }, + { + description: "limit invalid", + flagValues: fixtureFlagValues(func(flagValues map[string]string) { + flagValues[limitFlag] = "invalid" + }), + isValid: false, + }, + { + description: "limit invalid 2", + flagValues: fixtureFlagValues(func(flagValues map[string]string) { + flagValues[limitFlag] = "0" + }), + isValid: false, + }, } for _, tt := range tests { @@ -99,6 +116,8 @@ func TestParseFlags(t *testing.T) { t.Fatalf("configure global flag --%s: %v", projectIdFlag, err) } + configureFlags(cmd) + for flag, value := range tt.flagValues { err := cmd.Flags().Set(flag, value) if err != nil { @@ -117,7 +136,7 @@ func TestParseFlags(t *testing.T) { t.Fatalf("error validating flags: %v", err) } - model, err := parseFlags() + model, err := parseFlags(cmd) if err != nil { if !tt.isValid { return