diff --git a/internal/cli/atlas_alerts_acknowledge.go b/internal/cli/atlas_alerts_acknowledge.go index 01a8904fdd..b69ea68a90 100644 --- a/internal/cli/atlas_alerts_acknowledge.go +++ b/internal/cli/atlas_alerts_acknowledge.go @@ -27,7 +27,7 @@ import ( ) type atlasAlertsAcknowledgeOpts struct { - *globalOpts + globalOpts alertID string until string comment string @@ -73,9 +73,7 @@ func (opts *atlasAlertsAcknowledgeOpts) newAcknowledgeRequest() *atlas.Acknowled // mongocli atlas alerts acknowledge alertID --projectId projectId func AtlasAlertsAcknowledgeBuilder() *cobra.Command { - opts := &atlasAlertsAcknowledgeOpts{ - globalOpts: newGlobalOpts(), - } + opts := new(atlasAlertsAcknowledgeOpts) cmd := &cobra.Command{ Use: "acknowledge [alertId]", Short: description.AcknowledgeAlerts, diff --git a/internal/cli/atlas_alerts_acknowledge_test.go b/internal/cli/atlas_alerts_acknowledge_test.go index 0ed4ef789c..c2e4afdbb4 100644 --- a/internal/cli/atlas_alerts_acknowledge_test.go +++ b/internal/cli/atlas_alerts_acknowledge_test.go @@ -31,11 +31,10 @@ func TestAtlasAlertsAcknowledge_Run(t *testing.T) { expected := fixtures.Alert() acknowledgeOpts := &atlasAlertsAcknowledgeOpts{ - globalOpts: newGlobalOpts(), - alertID: "533dc40ae4b00835ff81eaee", - until: "", - comment: "Test", - store: mockStore, + alertID: "533dc40ae4b00835ff81eaee", + until: "", + comment: "Test", + store: mockStore, } ackReq := acknowledgeOpts.newAcknowledgeRequest() diff --git a/internal/cli/atlas_alerts_config_create.go b/internal/cli/atlas_alerts_config_create.go index 01b67f0e20..9420f10e05 100644 --- a/internal/cli/atlas_alerts_config_create.go +++ b/internal/cli/atlas_alerts_config_create.go @@ -38,8 +38,8 @@ const ( ) type atlasAlertsConfigCreateOpts struct { - *globalOpts - *atlasAlertsConfigOpts + globalOpts + atlasAlertsConfigOpts store store.AlertConfigurationCreator } @@ -69,10 +69,7 @@ func (opts *atlasAlertsConfigCreateOpts) Run() error { // [--notificationEmailAddress email --notificationMobileNumber number --notificationChannelName channel --notificationApiToken --notificationRegion region] // [--projectId projectId] func AtlasAlertsConfigCreateBuilder() *cobra.Command { - opts := &atlasAlertsConfigCreateOpts{ - globalOpts: newGlobalOpts(), - atlasAlertsConfigOpts: newAtlasAlertsConfigOpts(), - } + opts := new(atlasAlertsConfigCreateOpts) cmd := &cobra.Command{ Use: "create", Short: description.CreateAlertsConfig, diff --git a/internal/cli/atlas_alerts_config_create_test.go b/internal/cli/atlas_alerts_config_create_test.go index 3bd456130b..01e4d2d739 100644 --- a/internal/cli/atlas_alerts_config_create_test.go +++ b/internal/cli/atlas_alerts_config_create_test.go @@ -31,8 +31,7 @@ func TestAtlasAlertsConfigCreate_Run(t *testing.T) { expected := fixtures.AlertConfig() createOpts := &atlasAlertsConfigCreateOpts{ - globalOpts: newGlobalOpts(), - atlasAlertsConfigOpts: &atlasAlertsConfigOpts{ + atlasAlertsConfigOpts: atlasAlertsConfigOpts{ event: "OUTSIDE_METRIC_THRESHOLD", enabled: true, matcherFieldName: "HOSTNAME_AND_PORT", diff --git a/internal/cli/atlas_alerts_config_delete.go b/internal/cli/atlas_alerts_config_delete.go index c7c8764d10..5afda0e2f0 100644 --- a/internal/cli/atlas_alerts_config_delete.go +++ b/internal/cli/atlas_alerts_config_delete.go @@ -23,8 +23,8 @@ import ( ) type atlasAlertsConfigDeleteOpts struct { - *globalOpts - *deleteOpts + globalOpts + deleteOpts store store.AlertConfigurationDeleter } @@ -44,13 +44,9 @@ func (opts *atlasAlertsConfigDeleteOpts) Run() error { // mongocli atlas alerts config(s) delete id --projectId projectId [--confirm] func AtlasAlertsConfigDeleteBuilder() *cobra.Command { - opts := &atlasAlertsConfigDeleteOpts{ - globalOpts: newGlobalOpts(), - deleteOpts: &deleteOpts{ - successMessage: "Alert config '%s' deleted\n", - failMessage: "Alert config not deleted", - }, - } + opts := new(atlasAlertsConfigDeleteOpts) + opts.successMessage = "Alert config '%s' deleted\n" + opts.failMessage = "Alert config not deleted" cmd := &cobra.Command{ Use: "delete [id]", Short: description.DeleteAlertsConfig, diff --git a/internal/cli/atlas_alerts_config_delete_test.go b/internal/cli/atlas_alerts_config_delete_test.go index 66d19a8067..9de378f1ad 100644 --- a/internal/cli/atlas_alerts_config_delete_test.go +++ b/internal/cli/atlas_alerts_config_delete_test.go @@ -28,14 +28,11 @@ func TestAtlasAlertsConfigsDelete_Run(t *testing.T) { defer ctrl.Finish() deleteOpts := &atlasAlertsConfigDeleteOpts{ - globalOpts: newGlobalOpts(), - deleteOpts: &deleteOpts{ - confirm: true, - entry: "test", - successMessage: "Alert config '%s' deleted\n", - }, store: mockStore, } + deleteOpts.confirm = true + deleteOpts.entry = "test" + deleteOpts.successMessage = "Alert config '%s' deleted\n" mockStore. EXPECT(). diff --git a/internal/cli/atlas_alerts_config_list.go b/internal/cli/atlas_alerts_config_list.go index f921484050..57b4521a77 100644 --- a/internal/cli/atlas_alerts_config_list.go +++ b/internal/cli/atlas_alerts_config_list.go @@ -15,7 +15,6 @@ package cli import ( - atlas "github.com/mongodb/go-client-mongodb-atlas/mongodbatlas" "github.com/mongodb/mongocli/internal/description" "github.com/mongodb/mongocli/internal/flags" "github.com/mongodb/mongocli/internal/json" @@ -25,10 +24,9 @@ import ( ) type atlasAlertsConfigListOpts struct { - *globalOpts - pageNum int - itemsPerPage int - store store.AlertConfigurationLister + globalOpts + listOpts + store store.AlertConfigurationLister } func (opts *atlasAlertsConfigListOpts) init() error { @@ -52,18 +50,9 @@ func (opts *atlasAlertsConfigListOpts) Run() error { return json.PrettyPrint(result) } -func (opts *atlasAlertsConfigListOpts) newListOptions() *atlas.ListOptions { - return &atlas.ListOptions{ - PageNum: opts.pageNum, - ItemsPerPage: opts.itemsPerPage, - } -} - // mongocli atlas alerts config(s) list --projectId projectId [--page N] [--limit N] func AtlasAlertsConfigListBuilder() *cobra.Command { - opts := &atlasAlertsConfigListOpts{ - globalOpts: newGlobalOpts(), - } + opts := new(atlasAlertsConfigListOpts) cmd := &cobra.Command{ Use: "list", Short: description.ListAlertsConfigs, diff --git a/internal/cli/atlas_alerts_config_list_test.go b/internal/cli/atlas_alerts_config_list_test.go index 3a3ff68702..cf0dc3c031 100644 --- a/internal/cli/atlas_alerts_config_list_test.go +++ b/internal/cli/atlas_alerts_config_list_test.go @@ -31,8 +31,7 @@ func TestAtlasAlertsConfigList_Run(t *testing.T) { expected := fixtures.AlertConfigs() listOpts := &atlasAlertsConfigListOpts{ - globalOpts: newGlobalOpts(), - store: mockStore, + store: mockStore, } mockStore. diff --git a/internal/cli/atlas_alerts_config_update.go b/internal/cli/atlas_alerts_config_update.go index 7b03e51461..43d7678a32 100644 --- a/internal/cli/atlas_alerts_config_update.go +++ b/internal/cli/atlas_alerts_config_update.go @@ -24,8 +24,8 @@ import ( ) type atlasAlertsConfigUpdateOpts struct { - *globalOpts - *atlasAlertsConfigOpts + globalOpts + atlasAlertsConfigOpts store store.AlertConfigurationUpdater alertID string } @@ -57,10 +57,7 @@ func (opts *atlasAlertsConfigUpdateOpts) Run() error { // [--notificationEmailAddress email --notificationMobileNumber number --notificationChannelName channel --notificationApiToken --notificationRegion region] // [--projectId projectId] func AtlasAlertsConfigUpdateBuilder() *cobra.Command { - opts := &atlasAlertsConfigUpdateOpts{ - globalOpts: newGlobalOpts(), - atlasAlertsConfigOpts: newAtlasAlertsConfigOpts(), - } + opts := new(atlasAlertsConfigUpdateOpts) cmd := &cobra.Command{ Use: "update", Short: description.UpdateAlertsConfig, diff --git a/internal/cli/atlas_alerts_config_update_test.go b/internal/cli/atlas_alerts_config_update_test.go index 4e7ffc53ff..9c8774a9ee 100644 --- a/internal/cli/atlas_alerts_config_update_test.go +++ b/internal/cli/atlas_alerts_config_update_test.go @@ -31,8 +31,7 @@ func TestAtlasAlertsConfigUpdates_Run(t *testing.T) { expected := fixtures.AlertConfig() updateOpts := &atlasAlertsConfigUpdateOpts{ - globalOpts: newGlobalOpts(), - atlasAlertsConfigOpts: &atlasAlertsConfigOpts{ + atlasAlertsConfigOpts: atlasAlertsConfigOpts{ event: "OUTSIDE_METRIC_THRESHOLD", enabled: true, matcherFieldName: "HOSTNAME_AND_PORT", diff --git a/internal/cli/atlas_alerts_describe.go b/internal/cli/atlas_alerts_describe.go index 6a8307097c..2a3173772b 100644 --- a/internal/cli/atlas_alerts_describe.go +++ b/internal/cli/atlas_alerts_describe.go @@ -24,7 +24,7 @@ import ( ) type atlasAlertsDescribeOpts struct { - *globalOpts + globalOpts alertID string store store.AlertDescriber } @@ -50,9 +50,7 @@ func (opts *atlasAlertsDescribeOpts) Run() error { // mongocli atlas alerts describe alertID --projectId projectId func AtlasAlertsDescribeBuilder() *cobra.Command { - opts := &atlasAlertsDescribeOpts{ - globalOpts: newGlobalOpts(), - } + opts := new(atlasAlertsDescribeOpts) cmd := &cobra.Command{ Use: "describe [alertID]", Short: description.DescribeAlert, diff --git a/internal/cli/atlas_alerts_describe_test.go b/internal/cli/atlas_alerts_describe_test.go index 738fbeb198..a90bfa8575 100644 --- a/internal/cli/atlas_alerts_describe_test.go +++ b/internal/cli/atlas_alerts_describe_test.go @@ -31,9 +31,8 @@ func TestAtlasAlertsDescribe_Run(t *testing.T) { expected := fixtures.Alert() describeOpts := &atlasAlertsDescribeOpts{ - globalOpts: newGlobalOpts(), - alertID: "533dc40ae4b00835ff81eaee", - store: mockStore, + alertID: "533dc40ae4b00835ff81eaee", + store: mockStore, } mockStore. diff --git a/internal/cli/atlas_alerts_list.go b/internal/cli/atlas_alerts_list.go index f4bd32634c..3fa537cb18 100644 --- a/internal/cli/atlas_alerts_list.go +++ b/internal/cli/atlas_alerts_list.go @@ -25,11 +25,10 @@ import ( ) type atlasAlertsListOpts struct { - *globalOpts - pageNum int - itemsPerPage int - status string - store store.AlertLister + globalOpts + listOpts + status string + store store.AlertLister } func (opts *atlasAlertsListOpts) init() error { @@ -54,20 +53,17 @@ func (opts *atlasAlertsListOpts) Run() error { } func (opts *atlasAlertsListOpts) newAlertsListOptions() *atlas.AlertsListOptions { - return &atlas.AlertsListOptions{ - Status: opts.status, - ListOptions: atlas.ListOptions{ - PageNum: opts.pageNum, - ItemsPerPage: opts.itemsPerPage, - }, - } + o := new(atlas.AlertsListOptions) + o.Status = opts.status + o.ItemsPerPage = opts.itemsPerPage + o.PageNum = opts.pageNum + + return o } // mongocli atlas alerts list [--status status] [--projectId projectId] [--page N] [--limit N] func AtlasAlertsListBuilder() *cobra.Command { - opts := &atlasAlertsListOpts{ - globalOpts: newGlobalOpts(), - } + opts := new(atlasAlertsListOpts) cmd := &cobra.Command{ Use: "list", Short: description.ListAlerts, diff --git a/internal/cli/atlas_alerts_list_test.go b/internal/cli/atlas_alerts_list_test.go index 9538aaa589..56666c7fc2 100644 --- a/internal/cli/atlas_alerts_list_test.go +++ b/internal/cli/atlas_alerts_list_test.go @@ -31,9 +31,8 @@ func TestAtlasAlertsList_Run(t *testing.T) { expected := fixtures.AlertsResponse() listOpts := &atlasAlertsListOpts{ - globalOpts: newGlobalOpts(), - store: mockStore, - status: "OPEN", + store: mockStore, + status: "OPEN", } mockStore. diff --git a/internal/cli/atlas_backups_checkpoints_list.go b/internal/cli/atlas_backups_checkpoints_list.go index f9fe132de0..6ebfab1c47 100644 --- a/internal/cli/atlas_backups_checkpoints_list.go +++ b/internal/cli/atlas_backups_checkpoints_list.go @@ -15,7 +15,6 @@ package cli import ( - atlas "github.com/mongodb/go-client-mongodb-atlas/mongodbatlas" "github.com/mongodb/mongocli/internal/description" "github.com/mongodb/mongocli/internal/flags" "github.com/mongodb/mongocli/internal/json" @@ -25,11 +24,10 @@ import ( ) type atlasBackupsCheckpointsListOpts struct { - *globalOpts - clusterName string - pageNum int - itemsPerPage int - store store.CheckpointsLister + globalOpts + listOpts + clusterName string + store store.CheckpointsLister } func (opts *atlasBackupsCheckpointsListOpts) init() error { @@ -54,18 +52,9 @@ func (opts *atlasBackupsCheckpointsListOpts) Run() error { return json.PrettyPrint(result) } -func (opts *atlasBackupsCheckpointsListOpts) newListOptions() *atlas.ListOptions { - return &atlas.ListOptions{ - PageNum: opts.pageNum, - ItemsPerPage: opts.itemsPerPage, - } -} - // mongocli atlas backup(s) checkpoint(s) list clusterName [--projectId projectId] func AtlasBackupsCheckpointsListBuilder() *cobra.Command { - opts := &atlasBackupsCheckpointsListOpts{ - globalOpts: newGlobalOpts(), - } + opts := new(atlasBackupsCheckpointsListOpts) cmd := &cobra.Command{ Use: "list", Aliases: []string{"ls"}, diff --git a/internal/cli/atlas_backups_checkpoints_list_test.go b/internal/cli/atlas_backups_checkpoints_list_test.go index 286cbad46c..aa96b8870e 100644 --- a/internal/cli/atlas_backups_checkpoints_list_test.go +++ b/internal/cli/atlas_backups_checkpoints_list_test.go @@ -31,7 +31,6 @@ func TestAtlasBackupsCheckpointsList_Run(t *testing.T) { expected := fixtures.Checkpoints() listOpts := &atlasBackupsCheckpointsListOpts{ - globalOpts: newGlobalOpts(), store: mockStore, clusterName: "Cluster0", } diff --git a/internal/cli/atlas_backups_restores_list.go b/internal/cli/atlas_backups_restores_list.go index af39521583..c500facbd9 100644 --- a/internal/cli/atlas_backups_restores_list.go +++ b/internal/cli/atlas_backups_restores_list.go @@ -15,7 +15,6 @@ package cli import ( - atlas "github.com/mongodb/go-client-mongodb-atlas/mongodbatlas" "github.com/mongodb/mongocli/internal/description" "github.com/mongodb/mongocli/internal/flags" "github.com/mongodb/mongocli/internal/json" @@ -25,11 +24,10 @@ import ( ) type atlasBackupsRestoresListOpts struct { - *globalOpts - clusterName string - pageNum int - itemsPerPage int - store store.ContinuousJobLister + globalOpts + listOpts + clusterName string + store store.ContinuousJobLister } func (opts *atlasBackupsRestoresListOpts) init() error { @@ -53,18 +51,9 @@ func (opts *atlasBackupsRestoresListOpts) Run() error { return json.PrettyPrint(result) } -func (opts *atlasBackupsRestoresListOpts) newListOptions() *atlas.ListOptions { - return &atlas.ListOptions{ - PageNum: opts.pageNum, - ItemsPerPage: opts.itemsPerPage, - } -} - // mongocli atlas backup(s) restore(s) job(s) list [clusterName|clusterId] [--page N] [--limit N] func AtlasBackupsRestoresListBuilder() *cobra.Command { - opts := &atlasBackupsRestoresListOpts{ - globalOpts: newGlobalOpts(), - } + opts := new(atlasBackupsRestoresListOpts) cmd := &cobra.Command{ Use: "list [clusterName|clusterId]", Aliases: []string{"ls"}, diff --git a/internal/cli/atlas_backups_restores_list_test.go b/internal/cli/atlas_backups_restores_list_test.go index ee13224602..0873e899bd 100644 --- a/internal/cli/atlas_backups_restores_list_test.go +++ b/internal/cli/atlas_backups_restores_list_test.go @@ -31,7 +31,6 @@ func TestAtlasBackupsRestoresListOpts_Run(t *testing.T) { expected := fixtures.ContinuousJobs() listOpts := &atlasBackupsRestoresListOpts{ - globalOpts: newGlobalOpts(), store: mockStore, clusterName: "Cluster0", } diff --git a/internal/cli/atlas_backups_restores_start.go b/internal/cli/atlas_backups_restores_start.go index 1c0e4e08b1..fa344b91a4 100644 --- a/internal/cli/atlas_backups_restores_start.go +++ b/internal/cli/atlas_backups_restores_start.go @@ -35,7 +35,7 @@ const ( ) type atlasBackupsRestoresStartOpts struct { - *globalOpts + globalOpts method string clusterName string clusterID string @@ -192,9 +192,7 @@ func markRequiredAutomatedRestoreFlags(cmd *cobra.Command) error { // mongocli atlas backup(s) restore(s) job(s) start func AtlasBackupsRestoresStartBuilder() *cobra.Command { - opts := &atlasBackupsRestoresStartOpts{ - globalOpts: newGlobalOpts(), - } + opts := new(atlasBackupsRestoresStartOpts) cmd := &cobra.Command{ Use: fmt.Sprintf("start [%s|%s]", automatedRestore, httpRestore), Short: description.StartRestore, diff --git a/internal/cli/atlas_backups_restores_start_test.go b/internal/cli/atlas_backups_restores_start_test.go index 87494cc49e..6a9de9b8db 100644 --- a/internal/cli/atlas_backups_restores_start_test.go +++ b/internal/cli/atlas_backups_restores_start_test.go @@ -32,7 +32,6 @@ func TestAtlasBackupsRestoresStart_Run(t *testing.T) { t.Run(automatedRestore, func(t *testing.T) { listOpts := &atlasBackupsRestoresStartOpts{ - globalOpts: newGlobalOpts(), store: mockStore, method: automatedRestore, clusterName: "Cluster0", @@ -52,7 +51,6 @@ func TestAtlasBackupsRestoresStart_Run(t *testing.T) { t.Run(httpRestore, func(t *testing.T) { listOpts := &atlasBackupsRestoresStartOpts{ - globalOpts: newGlobalOpts(), store: mockStore, method: httpRestore, clusterName: "Cluster0", diff --git a/internal/cli/atlas_backups_snapshots_list.go b/internal/cli/atlas_backups_snapshots_list.go index 326decdb22..b3befb3738 100644 --- a/internal/cli/atlas_backups_snapshots_list.go +++ b/internal/cli/atlas_backups_snapshots_list.go @@ -15,7 +15,6 @@ package cli import ( - atlas "github.com/mongodb/go-client-mongodb-atlas/mongodbatlas" "github.com/mongodb/mongocli/internal/description" "github.com/mongodb/mongocli/internal/flags" "github.com/mongodb/mongocli/internal/json" @@ -25,11 +24,10 @@ import ( ) type atlasBackupsSnapshotsListOpts struct { - *globalOpts - clusterName string - pageNum int - itemsPerPage int - store store.SnapshotsLister + globalOpts + listOpts + clusterName string + store store.SnapshotsLister } func (opts *atlasBackupsSnapshotsListOpts) init() error { @@ -53,18 +51,9 @@ func (opts *atlasBackupsSnapshotsListOpts) Run() error { return json.PrettyPrint(result) } -func (opts *atlasBackupsSnapshotsListOpts) newListOptions() *atlas.ListOptions { - return &atlas.ListOptions{ - PageNum: opts.pageNum, - ItemsPerPage: opts.itemsPerPage, - } -} - // mongocli atlas backups snapshots list --projectId projectId [--page N] [--limit N] func AtlasBackupsSnapshotsListBuilder() *cobra.Command { - opts := &atlasBackupsSnapshotsListOpts{ - globalOpts: newGlobalOpts(), - } + opts := new(atlasBackupsSnapshotsListOpts) cmd := &cobra.Command{ Use: "list", Short: description.ListSnapshots, diff --git a/internal/cli/atlas_backups_snapshots_list_test.go b/internal/cli/atlas_backups_snapshots_list_test.go index 37e70203f3..88928bde09 100644 --- a/internal/cli/atlas_backups_snapshots_list_test.go +++ b/internal/cli/atlas_backups_snapshots_list_test.go @@ -31,7 +31,6 @@ func TestAtlasBackupsSnapshotsList_Run(t *testing.T) { expected := fixtures.ContinuousSnapshots() listOpts := &atlasBackupsSnapshotsListOpts{ - globalOpts: newGlobalOpts(), store: mockStore, clusterName: "Cluster0", } diff --git a/internal/cli/atlas_clusters_create.go b/internal/cli/atlas_clusters_create.go index c4242aeafd..dcf4dfc6a5 100644 --- a/internal/cli/atlas_clusters_create.go +++ b/internal/cli/atlas_clusters_create.go @@ -36,7 +36,7 @@ const ( ) type atlasClustersCreateOpts struct { - *globalOpts + globalOpts name string provider string region string @@ -148,8 +148,7 @@ func (opts *atlasClustersCreateOpts) newReplicationSpec() atlas.ReplicationSpec // create --projectId projectId --provider AWS|GCP|AZURE --region regionName [--members N] [--instanceSize M#] [--diskSizeGB N] [--backup] [--mdbVersion] func AtlasClustersCreateBuilder() *cobra.Command { opts := &atlasClustersCreateOpts{ - globalOpts: newGlobalOpts(), - fs: afero.NewOsFs(), + fs: afero.NewOsFs(), } cmd := &cobra.Command{ Use: "create [name]", diff --git a/internal/cli/atlas_clusters_create_test.go b/internal/cli/atlas_clusters_create_test.go index edb94939f2..f63c9259fa 100644 --- a/internal/cli/atlas_clusters_create_test.go +++ b/internal/cli/atlas_clusters_create_test.go @@ -33,7 +33,6 @@ func TestAtlasClustersCreate_Run(t *testing.T) { expected := fixtures.Cluster() createOpts := &atlasClustersCreateOpts{ - globalOpts: newGlobalOpts(), name: "ProjectBar", region: "US", instanceSize: atlasM2, @@ -91,10 +90,9 @@ func TestAtlasClustersCreate_Run(t *testing.T) { expected := fixtures.Cluster() createOpts := &atlasClustersCreateOpts{ - globalOpts: newGlobalOpts(), - filename: fileName, - fs: appFS, - store: mockStore, + filename: fileName, + fs: appFS, + store: mockStore, } cluster, _ := createOpts.newCluster() diff --git a/internal/cli/atlas_clusters_delete.go b/internal/cli/atlas_clusters_delete.go index f3d56a0c60..5a03c3d331 100644 --- a/internal/cli/atlas_clusters_delete.go +++ b/internal/cli/atlas_clusters_delete.go @@ -23,8 +23,8 @@ import ( ) type atlasClustersDeleteOpts struct { - *globalOpts - *deleteOpts + globalOpts + deleteOpts store store.ClusterDeleter } @@ -44,13 +44,9 @@ func (opts *atlasClustersDeleteOpts) Run() error { // mongocli atlas cluster(s) delete name --projectId projectId [--confirm] func AtlasClustersDeleteBuilder() *cobra.Command { - opts := &atlasClustersDeleteOpts{ - globalOpts: newGlobalOpts(), - deleteOpts: &deleteOpts{ - successMessage: "Cluster '%s' deleted\n", - failMessage: "Cluster not deleted", - }, - } + opts := &atlasClustersDeleteOpts{} + opts.successMessage = "Cluster '%s' deleted\n" + opts.failMessage = "Cluster not deleted" cmd := &cobra.Command{ Use: "delete [name]", Short: description.DeleteCluster, diff --git a/internal/cli/atlas_clusters_delete_test.go b/internal/cli/atlas_clusters_delete_test.go index 03e8cd7fc0..a1abc0ec20 100644 --- a/internal/cli/atlas_clusters_delete_test.go +++ b/internal/cli/atlas_clusters_delete_test.go @@ -28,8 +28,7 @@ func TestAtlasClustersDelete_Run(t *testing.T) { defer ctrl.Finish() deleteOpts := &atlasClustersDeleteOpts{ - globalOpts: newGlobalOpts(), - deleteOpts: &deleteOpts{ + deleteOpts: deleteOpts{ confirm: true, entry: "test", successMessage: "Cluster '%s' deleted\n", diff --git a/internal/cli/atlas_clusters_describe.go b/internal/cli/atlas_clusters_describe.go index bde1b2d176..37b14ed4f1 100644 --- a/internal/cli/atlas_clusters_describe.go +++ b/internal/cli/atlas_clusters_describe.go @@ -24,7 +24,7 @@ import ( ) type atlasClustersDescribeOpts struct { - *globalOpts + globalOpts name string store store.ClusterDescriber } @@ -50,9 +50,7 @@ func (opts *atlasClustersDescribeOpts) Run() error { // mongocli atlas cluster(s) describe [name] --projectId projectId func AtlasClustersDescribeBuilder() *cobra.Command { - opts := &atlasClustersDescribeOpts{ - globalOpts: newGlobalOpts(), - } + opts := &atlasClustersDescribeOpts{} cmd := &cobra.Command{ Use: "describe [name]", Short: description.DescribeCluster, diff --git a/internal/cli/atlas_clusters_describe_test.go b/internal/cli/atlas_clusters_describe_test.go index 21d4751eeb..da879c2212 100644 --- a/internal/cli/atlas_clusters_describe_test.go +++ b/internal/cli/atlas_clusters_describe_test.go @@ -31,9 +31,8 @@ func TestAtlasClustersDescribe_Run(t *testing.T) { expected := fixtures.Cluster() describeOpts := &atlasClustersDescribeOpts{ - globalOpts: newGlobalOpts(), - name: "test", - store: mockStore, + name: "test", + store: mockStore, } mockStore. diff --git a/internal/cli/atlas_clusters_indexes_create.go b/internal/cli/atlas_clusters_indexes_create.go index 0bee4f7b2f..8fbca9e6f7 100644 --- a/internal/cli/atlas_clusters_indexes_create.go +++ b/internal/cli/atlas_clusters_indexes_create.go @@ -27,7 +27,7 @@ import ( ) type atlasClustersIndexesCreateOpts struct { - *globalOpts + globalOpts clusterName string name string db string @@ -99,9 +99,7 @@ func (opts *atlasClustersIndexesCreateOpts) indexKeys() ([]map[string]string, er // AtlasClustersIndexesCreateBuilder builds a cobra.Command that can run as: // mcli atlas clusters index create [name] --clusterName clusterName --collectionName collectionName --dbName dbName [--key field:type] func AtlasClustersIndexesCreateBuilder() *cobra.Command { - opts := &atlasClustersIndexesCreateOpts{ - globalOpts: newGlobalOpts(), - } + opts := &atlasClustersIndexesCreateOpts{} cmd := &cobra.Command{ Use: "create [name]", Short: description.CreateCluster, diff --git a/internal/cli/atlas_clusters_indexes_create_test.go b/internal/cli/atlas_clusters_indexes_create_test.go index 5cc10e80ac..6080e1d6ca 100644 --- a/internal/cli/atlas_clusters_indexes_create_test.go +++ b/internal/cli/atlas_clusters_indexes_create_test.go @@ -28,7 +28,6 @@ func TestAtlasClustersIndexesCreate_Run(t *testing.T) { defer ctrl.Finish() createOpts := &atlasClustersIndexesCreateOpts{ - globalOpts: newGlobalOpts(), name: "ProjectBar", clusterName: "US", db: "test", diff --git a/internal/cli/atlas_clusters_list.go b/internal/cli/atlas_clusters_list.go index 66aee56d70..abb184e6aa 100644 --- a/internal/cli/atlas_clusters_list.go +++ b/internal/cli/atlas_clusters_list.go @@ -15,7 +15,6 @@ package cli import ( - atlas "github.com/mongodb/go-client-mongodb-atlas/mongodbatlas" "github.com/mongodb/mongocli/internal/description" "github.com/mongodb/mongocli/internal/flags" "github.com/mongodb/mongocli/internal/json" @@ -25,10 +24,9 @@ import ( ) type atlasClustersListOpts struct { - *globalOpts - pageNum int - itemsPerPage int - store store.ClusterLister + globalOpts + listOpts + store store.ClusterLister } func (opts *atlasClustersListOpts) init() error { @@ -52,18 +50,9 @@ func (opts *atlasClustersListOpts) Run() error { return json.PrettyPrint(result) } -func (opts *atlasClustersListOpts) newListOptions() *atlas.ListOptions { - return &atlas.ListOptions{ - PageNum: opts.pageNum, - ItemsPerPage: opts.itemsPerPage, - } -} - // mongocli atlas cluster(s) list --projectId projectId [--page N] [--limit N] func AtlasClustersListBuilder() *cobra.Command { - opts := &atlasClustersListOpts{ - globalOpts: newGlobalOpts(), - } + opts := &atlasClustersListOpts{} cmd := &cobra.Command{ Use: "list", Short: description.ListClusters, diff --git a/internal/cli/atlas_clusters_list_test.go b/internal/cli/atlas_clusters_list_test.go index a1c410d7a2..3e299f6435 100644 --- a/internal/cli/atlas_clusters_list_test.go +++ b/internal/cli/atlas_clusters_list_test.go @@ -31,8 +31,7 @@ func TestAtlasClustersList_Run(t *testing.T) { expected := fixtures.Clusters() listOpts := &atlasClustersListOpts{ - globalOpts: newGlobalOpts(), - store: mockStore, + store: mockStore, } mockStore. diff --git a/internal/cli/atlas_clusters_update.go b/internal/cli/atlas_clusters_update.go index 82f75d5842..8f2b39e330 100644 --- a/internal/cli/atlas_clusters_update.go +++ b/internal/cli/atlas_clusters_update.go @@ -27,7 +27,7 @@ import ( ) type atlasClustersUpdateOpts struct { - *globalOpts + globalOpts name string instanceSize string diskSizeGB float64 @@ -107,8 +107,7 @@ func (opts *atlasClustersUpdateOpts) patchOpts(out *atlas.Cluster) { // mongocli atlas cluster(s) update name --projectId projectId [--instanceSize M#] [--diskSizeGB N] [--mdbVersion] func AtlasClustersUpdateBuilder() *cobra.Command { opts := &atlasClustersUpdateOpts{ - globalOpts: newGlobalOpts(), - fs: afero.NewOsFs(), + fs: afero.NewOsFs(), } cmd := &cobra.Command{ Use: "update [name]", diff --git a/internal/cli/atlas_clusters_update_test.go b/internal/cli/atlas_clusters_update_test.go index b0e52fd0d6..bf764e10b6 100644 --- a/internal/cli/atlas_clusters_update_test.go +++ b/internal/cli/atlas_clusters_update_test.go @@ -33,7 +33,6 @@ func TestAtlasClustersUpdate_Run(t *testing.T) { expected := fixtures.Cluster() createOpts := &atlasClustersUpdateOpts{ - globalOpts: newGlobalOpts(), name: "ProjectBar", instanceSize: atlasM2, diskSizeGB: 10, @@ -95,10 +94,9 @@ func TestAtlasClustersUpdate_Run(t *testing.T) { expected := fixtures.Cluster() createOpts := &atlasClustersUpdateOpts{ - globalOpts: newGlobalOpts(), - filename: fileName, - fs: appFS, - store: mockStore, + filename: fileName, + fs: appFS, + store: mockStore, } cluster, _ := createOpts.cluster() diff --git a/internal/cli/atlas_dbusers_create.go b/internal/cli/atlas_dbusers_create.go index 0cf5607eba..33fbdeac5e 100644 --- a/internal/cli/atlas_dbusers_create.go +++ b/internal/cli/atlas_dbusers_create.go @@ -29,7 +29,7 @@ import ( ) type atlasDBUsersCreateOpts struct { - *globalOpts + globalOpts username string password string authDB string @@ -80,9 +80,7 @@ func (opts *atlasDBUsersCreateOpts) Prompt() error { // mongocli atlas dbuser(s) create --username username --password password --role roleName@dbName [--projectId projectId] func AtlasDBUsersCreateBuilder() *cobra.Command { - opts := &atlasDBUsersCreateOpts{ - globalOpts: newGlobalOpts(), - } + opts := &atlasDBUsersCreateOpts{} cmd := &cobra.Command{ Use: "create", Short: description.CreateDBUser, diff --git a/internal/cli/atlas_dbusers_create_test.go b/internal/cli/atlas_dbusers_create_test.go index fb1ff6ca19..05177b90cf 100644 --- a/internal/cli/atlas_dbusers_create_test.go +++ b/internal/cli/atlas_dbusers_create_test.go @@ -31,11 +31,10 @@ func TestAtlasDBUserCreate_Run(t *testing.T) { expected := fixtures.DatabaseUser() createOpts := &atlasDBUsersCreateOpts{ - globalOpts: newGlobalOpts(), - username: "ProjectBar", - password: "US", - roles: []string{"admin@admin"}, - store: mockStore, + username: "ProjectBar", + password: "US", + roles: []string{"admin@admin"}, + store: mockStore, } mockStore. diff --git a/internal/cli/atlas_dbusers_delete.go b/internal/cli/atlas_dbusers_delete.go index 384ec9d1a4..892540dfa5 100644 --- a/internal/cli/atlas_dbusers_delete.go +++ b/internal/cli/atlas_dbusers_delete.go @@ -24,8 +24,8 @@ import ( ) type atlasDBUsersDeleteOpts struct { - *globalOpts - *deleteOpts + globalOpts + deleteOpts authDB string store store.DatabaseUserDeleter } @@ -46,13 +46,9 @@ func (opts *atlasDBUsersDeleteOpts) Run() error { // mongocli atlas dbuser(s) delete --force func AtlasDBUsersDeleteBuilder() *cobra.Command { - opts := &atlasDBUsersDeleteOpts{ - globalOpts: newGlobalOpts(), - deleteOpts: &deleteOpts{ - successMessage: "DB user '%s' deleted\n", - failMessage: "DB user not deleted", - }, - } + opts := &atlasDBUsersDeleteOpts{} + opts.successMessage = "DB user '%s' deleted\n" + opts.failMessage = "DB user not deleted" cmd := &cobra.Command{ Use: "delete [username]", Short: description.DeleteDBUser, diff --git a/internal/cli/atlas_dbusers_delete_test.go b/internal/cli/atlas_dbusers_delete_test.go index 97b4252566..b69f19f13e 100644 --- a/internal/cli/atlas_dbusers_delete_test.go +++ b/internal/cli/atlas_dbusers_delete_test.go @@ -28,8 +28,7 @@ func TestAtlasDBUsersDelete_Run(t *testing.T) { defer ctrl.Finish() deleteOpts := &atlasDBUsersDeleteOpts{ - globalOpts: newGlobalOpts(), - deleteOpts: &deleteOpts{ + deleteOpts: deleteOpts{ confirm: true, entry: "test", successMessage: "DB user '%s' deleted\n", diff --git a/internal/cli/atlas_dbusers_list.go b/internal/cli/atlas_dbusers_list.go index d5705cf114..2e8d3d6a82 100644 --- a/internal/cli/atlas_dbusers_list.go +++ b/internal/cli/atlas_dbusers_list.go @@ -14,7 +14,6 @@ package cli import ( - atlas "github.com/mongodb/go-client-mongodb-atlas/mongodbatlas" "github.com/mongodb/mongocli/internal/description" "github.com/mongodb/mongocli/internal/flags" "github.com/mongodb/mongocli/internal/json" @@ -24,10 +23,9 @@ import ( ) type atlasDBUsersListOpts struct { - *globalOpts - pageNum int - itemsPerPage int - store store.DatabaseUserLister + globalOpts + listOpts + store store.DatabaseUserLister } func (opts *atlasDBUsersListOpts) init() error { @@ -51,18 +49,9 @@ func (opts *atlasDBUsersListOpts) Run() error { return json.PrettyPrint(result) } -func (opts *atlasDBUsersListOpts) newListOptions() *atlas.ListOptions { - return &atlas.ListOptions{ - PageNum: opts.pageNum, - ItemsPerPage: opts.itemsPerPage, - } -} - // mongocli atlas dbuser(s) list --projectId projectId [--page N] [--limit N] func AtlasDBUsersListBuilder() *cobra.Command { - opts := &atlasDBUsersListOpts{ - globalOpts: newGlobalOpts(), - } + opts := new(atlasDBUsersListOpts) cmd := &cobra.Command{ Use: "list", Short: description.ListDBUsers, diff --git a/internal/cli/atlas_dbusers_list_test.go b/internal/cli/atlas_dbusers_list_test.go index 7aec4f542f..0837996617 100644 --- a/internal/cli/atlas_dbusers_list_test.go +++ b/internal/cli/atlas_dbusers_list_test.go @@ -30,8 +30,7 @@ func TestAtlasDBUserList_Run(t *testing.T) { expected := fixtures.DatabaseUsers() listOpts := &atlasDBUsersListOpts{ - globalOpts: newGlobalOpts(), - store: mockStore, + store: mockStore, } mockStore. diff --git a/internal/cli/atlas_dbusers_update.go b/internal/cli/atlas_dbusers_update.go index c1e8e82b0a..8cebaa4c77 100644 --- a/internal/cli/atlas_dbusers_update.go +++ b/internal/cli/atlas_dbusers_update.go @@ -26,7 +26,7 @@ import ( ) type atlasDBUsersUpdateOpts struct { - *globalOpts + globalOpts username string password string roles []string @@ -57,7 +57,6 @@ func (opts *atlasDBUsersUpdateOpts) Run() error { } func (opts *atlasDBUsersUpdateOpts) update(out *atlas.DatabaseUser) { - out.GroupID = opts.ProjectID() out.Username = opts.username if opts.password != "" { @@ -69,9 +68,7 @@ func (opts *atlasDBUsersUpdateOpts) update(out *atlas.DatabaseUser) { // mongocli atlas dbuser(s) update username [--password password] [--role roleName@dbName] [--projectId projectId] func AtlasDBUsersUpdateBuilder() *cobra.Command { - opts := &atlasDBUsersUpdateOpts{ - globalOpts: newGlobalOpts(), - } + opts := &atlasDBUsersUpdateOpts{} cmd := &cobra.Command{ Use: "update [username]", Short: description.UpdateDBUser, diff --git a/internal/cli/atlas_dbusers_update_test.go b/internal/cli/atlas_dbusers_update_test.go index df8af229ce..734aaec736 100644 --- a/internal/cli/atlas_dbusers_update_test.go +++ b/internal/cli/atlas_dbusers_update_test.go @@ -32,11 +32,10 @@ func TestAtlasDBUserUpdate_Run(t *testing.T) { expected := fixtures.DatabaseUser() updateOpts := &atlasDBUsersUpdateOpts{ - globalOpts: newGlobalOpts(), - username: "test4", - password: "US", - roles: []string{"admin@admin"}, - store: mockStore, + username: "test4", + password: "US", + roles: []string{"admin@admin"}, + store: mockStore, } dbUser := atlas.DatabaseUser{} diff --git a/internal/cli/atlas_events_list.go b/internal/cli/atlas_events_list.go index 67d4f3d91c..445554090c 100644 --- a/internal/cli/atlas_events_list.go +++ b/internal/cli/atlas_events_list.go @@ -26,13 +26,12 @@ import ( ) type atlasEventsListOpts struct { - *globalOpts - pageNum int - itemsPerPage int - eventType string - minDate string - maxDate string - store store.EventsStore + globalOpts + listOpts + eventType string + minDate string + maxDate string + store store.EventsStore } func (opts *atlasEventsListOpts) init() error { @@ -63,7 +62,6 @@ func (opts *atlasEventsListOpts) Run() error { } func (opts *atlasEventsListOpts) newEventListOptions() *atlas.EventListOptions { - return &atlas.EventListOptions{ ListOptions: atlas.ListOptions{ PageNum: opts.pageNum, @@ -77,9 +75,7 @@ func (opts *atlasEventsListOpts) newEventListOptions() *atlas.EventListOptions { // mongocli atlas event(s) list [--projectId projectId] [--source source][--type type] [--page N] [--limit N] [--mindate minDate] [--maxDate maxDate] func AtlasEventsListBuilder() *cobra.Command { - opts := &atlasEventsListOpts{ - globalOpts: newGlobalOpts(), - } + opts := &atlasEventsListOpts{} cmd := &cobra.Command{ Use: "list", Short: description.ListEvents, diff --git a/internal/cli/atlas_events_list_test.go b/internal/cli/atlas_events_list_test.go index 82444537b2..68f9d4be94 100644 --- a/internal/cli/atlas_events_list_test.go +++ b/internal/cli/atlas_events_list_test.go @@ -8,7 +8,7 @@ import ( "github.com/mongodb/mongocli/internal/mocks" ) -func TestAtlasOrganizationEventsList_Run(t *testing.T) { +func TestAtlasEventsList_Run(t *testing.T) { ctrl := gomock.NewController(t) mockStore := mocks.NewMockEventsStore(ctrl) @@ -16,44 +16,36 @@ func TestAtlasOrganizationEventsList_Run(t *testing.T) { expected := fixtures.Events() - listOpts := &atlasEventsListOpts{ - globalOpts: newGlobalOpts(), - store: mockStore, - } - listOpts.orgID = "1" - - mockStore. - EXPECT().OrganizationEvents(listOpts.orgID, listOpts.newEventListOptions()). - Return(expected, nil). - Times(1) - - err := listOpts.Run() - if err != nil { - t.Fatalf("Run() unexpected error: %v", err) - } -} - -func TestAtlasProjectEventsList_Run(t *testing.T) { - ctrl := gomock.NewController(t) - mockStore := mocks.NewMockEventsStore(ctrl) - - defer ctrl.Finish() - - expected := fixtures.Events() - - listOpts := &atlasEventsListOpts{ - globalOpts: newGlobalOpts(), - store: mockStore, - } - - listOpts.projectID = "1" - mockStore. - EXPECT().ProjectEvents(listOpts.projectID, &listOpts.newEventListOptions().ListOptions). - Return(expected, nil). - Times(1) - - err := listOpts.Run() - if err != nil { - t.Fatalf("Run() unexpected error: %v", err) - } + t.Run("for a project", func(t *testing.T) { + listOpts := &atlasEventsListOpts{ + store: mockStore, + } + listOpts.orgID = "1" + + mockStore. + EXPECT().OrganizationEvents(listOpts.orgID, listOpts.newEventListOptions()). + Return(expected, nil). + Times(1) + + err := listOpts.Run() + if err != nil { + t.Fatalf("Run() unexpected error: %v", err) + } + }) + t.Run("for an org", func(t *testing.T) { + listOpts := &atlasEventsListOpts{ + store: mockStore, + } + + listOpts.projectID = "1" + mockStore. + EXPECT().ProjectEvents(listOpts.projectID, &listOpts.newEventListOptions().ListOptions). + Return(expected, nil). + Times(1) + + err := listOpts.Run() + if err != nil { + t.Fatalf("Run() unexpected error: %v", err) + } + }) } diff --git a/internal/cli/atlas_measurements.go b/internal/cli/atlas_measurements.go index 072f05311e..ca78b74db3 100644 --- a/internal/cli/atlas_measurements.go +++ b/internal/cli/atlas_measurements.go @@ -15,16 +15,38 @@ package cli import ( + atlas "github.com/mongodb/go-client-mongodb-atlas/mongodbatlas" "github.com/mongodb/mongocli/internal/description" "github.com/spf13/cobra" ) +type measurementsOpts struct { + listOpts + granularity string + period string + start string + end string + measurementType string +} + +func (opts *measurementsOpts) newProcessMeasurementListOptions() *atlas.ProcessMeasurementListOptions { + o := &atlas.ProcessMeasurementListOptions{ + ListOptions: opts.newListOptions(), + } + o.Granularity = opts.granularity + o.Period = opts.period + o.Start = opts.start + o.End = opts.end + o.M = opts.measurementType + + return o +} + func AtlasMeasurementsBuilder() *cobra.Command { cmd := &cobra.Command{ Use: "measurements", Short: description.Measurements, } - cmd.AddCommand(AtlasMeasurementsProcessBuilder()) return cmd diff --git a/internal/cli/atlas_measurements_process.go b/internal/cli/atlas_measurements_processes.go similarity index 73% rename from internal/cli/atlas_measurements_process.go rename to internal/cli/atlas_measurements_processes.go index 39f4cb1e08..d590fb8e09 100644 --- a/internal/cli/atlas_measurements_process.go +++ b/internal/cli/atlas_measurements_processes.go @@ -15,7 +15,6 @@ package cli import ( - atlas "github.com/mongodb/go-client-mongodb-atlas/mongodbatlas" "github.com/mongodb/mongocli/internal/description" "github.com/mongodb/mongocli/internal/flags" "github.com/mongodb/mongocli/internal/json" @@ -25,17 +24,11 @@ import ( ) type atlasMeasurementsProcessOpts struct { - *globalOpts - pageNum int - itemsPerPage int - host string - port int - granularity string - period string - start string - end string - measurementType string - store store.ProcessMeasurementLister + globalOpts + measurementsOpts + host string + port int + store store.ProcessMeasurementLister } func (opts *atlasMeasurementsProcessOpts) init() error { @@ -59,29 +52,13 @@ func (opts *atlasMeasurementsProcessOpts) Run() error { return json.PrettyPrint(result) } -func (opts *atlasMeasurementsProcessOpts) newProcessMeasurementListOptions() *atlas.ProcessMeasurementListOptions { - return &atlas.ProcessMeasurementListOptions{ - ListOptions: &atlas.ListOptions{ - PageNum: opts.pageNum, - ItemsPerPage: opts.itemsPerPage, - }, - Granularity: opts.granularity, - Period: opts.period, - Start: opts.start, - End: opts.end, - M: opts.measurementType, - } -} - // mongocli atlas measurements process(es) host:port [--granularity granularity] [--period period] [--start start] [--end end] [--type type][--projectId projectId] func AtlasMeasurementsProcessBuilder() *cobra.Command { - opts := &atlasMeasurementsProcessOpts{ - globalOpts: newGlobalOpts(), - } + opts := &atlasMeasurementsProcessOpts{} cmd := &cobra.Command{ - Use: "process", + Use: "processes", Short: description.ProcessMeasurements, - Aliases: []string{"processes"}, + Aliases: []string{"process"}, Args: cobra.ExactArgs(1), PreRunE: func(cmd *cobra.Command, args []string) error { return opts.init() @@ -96,6 +73,8 @@ func AtlasMeasurementsProcessBuilder() *cobra.Command { return opts.Run() }, } + cmd.Flags().IntVar(&opts.pageNum, flags.Page, 0, usage.Page) + cmd.Flags().IntVar(&opts.itemsPerPage, flags.Limit, 0, usage.Limit) cmd.Flags().StringVar(&opts.granularity, flags.Granularity, "", usage.Granularity) cmd.Flags().StringVar(&opts.period, flags.Period, "", usage.Period) diff --git a/internal/cli/atlas_measurements_process_test.go b/internal/cli/atlas_measurements_processes_test.go similarity index 89% rename from internal/cli/atlas_measurements_process_test.go rename to internal/cli/atlas_measurements_processes_test.go index 7df7473fa7..1a86fa684b 100644 --- a/internal/cli/atlas_measurements_process_test.go +++ b/internal/cli/atlas_measurements_processes_test.go @@ -30,13 +30,12 @@ func TestAtlasMeasurementsProcess_Run(t *testing.T) { expected := fixtures.ProcessMeasurements() listOpts := &atlasMeasurementsProcessOpts{ - globalOpts: newGlobalOpts(), - host: "hard-00-00.mongodb.net", - port: 27017, - granularity: "PT1M", - period: "PT1M", - store: mockStore, + host: "hard-00-00.mongodb.net", + port: 27017, + store: mockStore, } + listOpts.granularity = "PT1M" + listOpts.period = "PT1M" hostName, port, err := GetHostNameAndPort("hard-00-00.mongodb.net:27017") if err != nil { diff --git a/internal/cli/atlas_whitelist_create.go b/internal/cli/atlas_whitelist_create.go index 526950ab9a..a2b0b1f94e 100644 --- a/internal/cli/atlas_whitelist_create.go +++ b/internal/cli/atlas_whitelist_create.go @@ -31,7 +31,7 @@ const ( ) type atlasWhitelistCreateOpts struct { - *globalOpts + globalOpts entry string entryType string comment string @@ -77,9 +77,7 @@ func (opts *atlasWhitelistCreateOpts) newWhitelist() *atlas.ProjectIPWhitelist { // mongocli atlas whitelist(s) create value --type cidrBlock|ipAddress [--comment comment] [--projectId projectId] func AtlasWhitelistCreateBuilder() *cobra.Command { - opts := &atlasWhitelistCreateOpts{ - globalOpts: newGlobalOpts(), - } + opts := &atlasWhitelistCreateOpts{} cmd := &cobra.Command{ Use: "create [entry]", Short: description.CreateWhitelist, diff --git a/internal/cli/atlas_whitelist_create_test.go b/internal/cli/atlas_whitelist_create_test.go index ee6cae31c6..e789acfc03 100644 --- a/internal/cli/atlas_whitelist_create_test.go +++ b/internal/cli/atlas_whitelist_create_test.go @@ -31,10 +31,9 @@ func TestAtlasWhitelistCreate_Run(t *testing.T) { expected := fixtures.ProjectIPWhitelist() createOpts := &atlasWhitelistCreateOpts{ - globalOpts: newGlobalOpts(), - entry: "37.228.254.100", - entryType: ipAddress, - store: mockStore, + entry: "37.228.254.100", + entryType: ipAddress, + store: mockStore, } mockStore. diff --git a/internal/cli/atlas_whitelist_delete.go b/internal/cli/atlas_whitelist_delete.go index ddac080718..0c247b1231 100644 --- a/internal/cli/atlas_whitelist_delete.go +++ b/internal/cli/atlas_whitelist_delete.go @@ -23,8 +23,8 @@ import ( ) type atlasWhitelistDeleteOpts struct { - *globalOpts - *deleteOpts + globalOpts + deleteOpts store store.ProjectIPWhitelistDeleter } @@ -45,8 +45,7 @@ func (opts *atlasWhitelistDeleteOpts) Run() error { // mongocli atlas whitelist delete --force func AtlasWhitelistDeleteBuilder() *cobra.Command { opts := &atlasWhitelistDeleteOpts{ - globalOpts: newGlobalOpts(), - deleteOpts: &deleteOpts{ + deleteOpts: deleteOpts{ successMessage: "Project whitelist entry '%s' deleted\n", failMessage: "Project whitelist entry not deleted", }, diff --git a/internal/cli/atlas_whitelist_delete_test.go b/internal/cli/atlas_whitelist_delete_test.go index 397c9b6818..76e5a63921 100644 --- a/internal/cli/atlas_whitelist_delete_test.go +++ b/internal/cli/atlas_whitelist_delete_test.go @@ -28,8 +28,7 @@ func TestAtlasWhitelistDelete_Run(t *testing.T) { defer ctrl.Finish() deleteOpts := &atlasWhitelistDeleteOpts{ - globalOpts: newGlobalOpts(), - deleteOpts: &deleteOpts{ + deleteOpts: deleteOpts{ confirm: true, entry: "test", successMessage: "Project whitelist entry '%s' deleted\n", diff --git a/internal/cli/atlas_whitelist_describe.go b/internal/cli/atlas_whitelist_describe.go index 5c91ac8094..568c3aefc1 100644 --- a/internal/cli/atlas_whitelist_describe.go +++ b/internal/cli/atlas_whitelist_describe.go @@ -24,7 +24,7 @@ import ( ) type atlasWhitelistDescribeOpts struct { - *globalOpts + globalOpts name string store store.ProjectIPWhitelistDescriber } @@ -50,9 +50,7 @@ func (opts *atlasWhitelistDescribeOpts) Run() error { // mongocli atlas whitelist(s) describe [name] --projectId projectId func AtlasWhitelistDescribeBuilder() *cobra.Command { - opts := &atlasWhitelistDescribeOpts{ - globalOpts: newGlobalOpts(), - } + opts := &atlasWhitelistDescribeOpts{} cmd := &cobra.Command{ Use: "describe [name]", Short: description.DescribeWhitelist, diff --git a/internal/cli/atlas_whitelist_describe_test.go b/internal/cli/atlas_whitelist_describe_test.go index 3b69e0629f..2d38c90af9 100644 --- a/internal/cli/atlas_whitelist_describe_test.go +++ b/internal/cli/atlas_whitelist_describe_test.go @@ -31,9 +31,8 @@ func TestAtlasWhitelistDescribe_Run(t *testing.T) { expected := fixtures.IPWhiteList() describeOpts := &atlasWhitelistDescribeOpts{ - globalOpts: newGlobalOpts(), - name: "test", - store: mockStore, + name: "test", + store: mockStore, } mockStore. diff --git a/internal/cli/atlas_whitelist_list.go b/internal/cli/atlas_whitelist_list.go index 9187d042f9..113763c32d 100644 --- a/internal/cli/atlas_whitelist_list.go +++ b/internal/cli/atlas_whitelist_list.go @@ -14,7 +14,6 @@ package cli import ( - atlas "github.com/mongodb/go-client-mongodb-atlas/mongodbatlas" "github.com/mongodb/mongocli/internal/description" "github.com/mongodb/mongocli/internal/flags" "github.com/mongodb/mongocli/internal/json" @@ -24,10 +23,9 @@ import ( ) type atlasWhitelistListOpts struct { - *globalOpts - pageNum int - itemsPerPage int - store store.ProjectIPWhitelistLister + globalOpts + listOpts + store store.ProjectIPWhitelistLister } func (opts *atlasWhitelistListOpts) init() error { @@ -51,18 +49,9 @@ func (opts *atlasWhitelistListOpts) Run() error { return json.PrettyPrint(result) } -func (opts *atlasWhitelistListOpts) newListOptions() *atlas.ListOptions { - return &atlas.ListOptions{ - PageNum: opts.pageNum, - ItemsPerPage: opts.itemsPerPage, - } -} - // mongocli atlas whitelist(s) list --projectId projectId [--page N] [--limit N] func AtlasWhitelistListBuilder() *cobra.Command { - opts := &atlasWhitelistListOpts{ - globalOpts: newGlobalOpts(), - } + opts := &atlasWhitelistListOpts{} cmd := &cobra.Command{ Use: "list", Short: description.ListWhitelist, diff --git a/internal/cli/atlas_whitelist_list_test.go b/internal/cli/atlas_whitelist_list_test.go index 9d6d8933ab..4c1a56acce 100644 --- a/internal/cli/atlas_whitelist_list_test.go +++ b/internal/cli/atlas_whitelist_list_test.go @@ -31,8 +31,7 @@ func TestAtlasWhitelistList_Run(t *testing.T) { expected := fixtures.ProjectIPWhitelist() listOpts := &atlasWhitelistListOpts{ - globalOpts: newGlobalOpts(), - store: mockStore, + store: mockStore, } mockStore. diff --git a/internal/cli/cli.go b/internal/cli/cli.go index 43f5a3a7aa..da6b3e3f3f 100644 --- a/internal/cli/cli.go +++ b/internal/cli/cli.go @@ -36,11 +36,6 @@ type globalOpts struct { projectID string } -// newGlobalOpts returns an globalOpts -func newGlobalOpts() *globalOpts { - return new(globalOpts) -} - // ProjectID returns the project id. // If the id is empty, it caches it after querying config. func (opts *globalOpts) ProjectID() string { @@ -126,11 +121,6 @@ func (opts *deleteOpts) FailMessage() string { return fallbackFailMessage } -// newAtlasAlertsConfigOpts returns an atlasAlertsConfigOpts -func newAtlasAlertsConfigOpts() *atlasAlertsConfigOpts { - return new(atlasAlertsConfigOpts) -} - // atlasAlertsConfigOpts contains all the information and functions to manage an alert configuration type atlasAlertsConfigOpts struct { event string @@ -253,6 +243,18 @@ func (opts *atlasAlertsConfigOpts) newMatcher() *atlas.Matcher { } } +type listOpts struct { + pageNum int + itemsPerPage int +} + +func (opts *listOpts) newListOptions() *atlas.ListOptions { + return &atlas.ListOptions{ + PageNum: opts.pageNum, + ItemsPerPage: opts.itemsPerPage, + } +} + // GetHostNameAndPort return the hostname and the port starting from the string hostname:port func GetHostNameAndPort(hostInfo string) (string, int, error) { host := strings.SplitN(hostInfo, ":", -1) diff --git a/internal/cli/cloud_manager.go b/internal/cli/cloud_manager.go index 42c922566f..89fcff78af 100644 --- a/internal/cli/cloud_manager.go +++ b/internal/cli/cloud_manager.go @@ -26,7 +26,7 @@ func CloudManagerBuilder() *cobra.Command { Short: description.CloudManager, } - cmd.AddCommand(CloudManagerClustersBuilder()) + cmd.AddCommand(OpsManagerClustersBuilder()) cmd.AddCommand(AtlasAlertsBuilder()) cmd.AddCommand(AtlasBackupsBuilder()) cmd.AddCommand(OpsManagerServersBuilder()) diff --git a/internal/cli/config.go b/internal/cli/config.go index f350cae49a..ad0b764c65 100644 --- a/internal/cli/config.go +++ b/internal/cli/config.go @@ -25,7 +25,7 @@ import ( ) type configOpts struct { - *globalOpts + globalOpts Service string PublicAPIKey string PrivateAPIKey string @@ -108,9 +108,7 @@ func (opts *configOpts) Run() error { } func ConfigBuilder() *cobra.Command { - opts := &configOpts{ - globalOpts: newGlobalOpts(), - } + opts := &configOpts{} cmd := &cobra.Command{ Use: "config", Short: description.ConfigDescription, diff --git a/internal/cli/config_set.go b/internal/cli/config_set.go index ff8f9a3534..db2a15a85d 100644 --- a/internal/cli/config_set.go +++ b/internal/cli/config_set.go @@ -24,7 +24,7 @@ import ( ) type configSetOpts struct { - *globalOpts + globalOpts prop string val string } @@ -39,9 +39,7 @@ func (opts *configSetOpts) Run() error { } func ConfigSetBuilder() *cobra.Command { - opts := &configSetOpts{ - globalOpts: newGlobalOpts(), - } + opts := &configSetOpts{} cmd := &cobra.Command{ Use: "set [prop] [val]", Short: description.SetConfig, diff --git a/internal/cli/iam_projects_create.go b/internal/cli/iam_projects_create.go index fe86fbf22f..19c7565c8b 100644 --- a/internal/cli/iam_projects_create.go +++ b/internal/cli/iam_projects_create.go @@ -24,7 +24,7 @@ import ( ) type iamProjectsCreateOpts struct { - *globalOpts + globalOpts name string store store.ProjectCreator } @@ -51,9 +51,7 @@ func (opts *iamProjectsCreateOpts) Run() error { // mongocli iam project(s) create name [--orgId orgId] func IAMProjectsCreateBuilder() *cobra.Command { - opts := &iamProjectsCreateOpts{ - globalOpts: newGlobalOpts(), - } + opts := &iamProjectsCreateOpts{} cmd := &cobra.Command{ Use: "create [name]", Short: description.CreateProject, diff --git a/internal/cli/iam_projects_create_test.go b/internal/cli/iam_projects_create_test.go index 3b299673d4..edaf8a53d8 100644 --- a/internal/cli/iam_projects_create_test.go +++ b/internal/cli/iam_projects_create_test.go @@ -36,9 +36,8 @@ func TestIAMProjectsCreate_Run(t *testing.T) { Times(1) createOpts := &iamProjectsCreateOpts{ - globalOpts: newGlobalOpts(), - store: mockStore, - name: "ProjectBar", + store: mockStore, + name: "ProjectBar", } createOpts.orgID = "5a0a1e7e0f2912c554080adc" err := createOpts.Run() diff --git a/internal/cli/iam_projects_list.go b/internal/cli/iam_projects_list.go index 03c527bcdc..25ebc6be4f 100644 --- a/internal/cli/iam_projects_list.go +++ b/internal/cli/iam_projects_list.go @@ -25,7 +25,7 @@ import ( ) type iamProjectsListOpts struct { - *globalOpts + globalOpts store store.ProjectLister } @@ -51,9 +51,7 @@ func (opts *iamProjectsListOpts) Run() error { // mongocli iam project(s) list [--orgId orgId] func IAMProjectsListBuilder() *cobra.Command { - opts := &iamProjectsListOpts{ - globalOpts: newGlobalOpts(), - } + opts := &iamProjectsListOpts{} cmd := &cobra.Command{ Use: "list", Aliases: []string{"ls"}, diff --git a/internal/cli/iam_projects_list_test.go b/internal/cli/iam_projects_list_test.go index af277f3124..4360ab6e72 100644 --- a/internal/cli/iam_projects_list_test.go +++ b/internal/cli/iam_projects_list_test.go @@ -39,8 +39,7 @@ func TestIAMProjectsList_Run(t *testing.T) { Times(1) listOpts := &iamProjectsListOpts{ - store: mockStore, - globalOpts: newGlobalOpts(), + store: mockStore, } err := listOpts.Run() if err != nil { @@ -56,8 +55,7 @@ func TestIAMProjectsList_Run(t *testing.T) { Times(1) listOpts := &iamProjectsListOpts{ - globalOpts: newGlobalOpts(), - store: mockStore, + store: mockStore, } listOpts.orgID = "1" config.SetService(config.OpsManagerService) @@ -75,8 +73,7 @@ func TestIAMProjectsList_Run(t *testing.T) { Times(1) listOpts := &iamProjectsListOpts{ - globalOpts: newGlobalOpts(), - store: mockStore, + store: mockStore, } listOpts.orgID = "1" config.SetService(config.CloudService) diff --git a/internal/cli/ops_manager.go b/internal/cli/ops_manager.go index a9b1c2ecf2..232040cd3c 100644 --- a/internal/cli/ops_manager.go +++ b/internal/cli/ops_manager.go @@ -26,7 +26,7 @@ func OpsManagerBuilder() *cobra.Command { Short: description.OpsManager, } - cmd.AddCommand(CloudManagerClustersBuilder()) + cmd.AddCommand(OpsManagerClustersBuilder()) cmd.AddCommand(AtlasAlertsBuilder()) cmd.AddCommand(AtlasBackupsBuilder()) cmd.AddCommand(OpsManagerServersBuilder()) diff --git a/internal/cli/ops_manager_alerts_global_list.go b/internal/cli/ops_manager_alerts_global_list.go index f789303b24..393d8d9e68 100644 --- a/internal/cli/ops_manager_alerts_global_list.go +++ b/internal/cli/ops_manager_alerts_global_list.go @@ -25,10 +25,9 @@ import ( ) type opsManagerAlertsGlobalListOpts struct { - store store.GlobalAlertLister - pageNum int - itemsPerPage int - status string + listOpts + status string + store store.GlobalAlertLister } func (opts *opsManagerAlertsGlobalListOpts) init() error { diff --git a/internal/cli/ops_manager_automation_show.go b/internal/cli/ops_manager_automation_show.go index 181122bb59..6cf89292ac 100644 --- a/internal/cli/ops_manager_automation_show.go +++ b/internal/cli/ops_manager_automation_show.go @@ -23,7 +23,7 @@ import ( ) type opsManagerAutomationShowOpts struct { - *globalOpts + globalOpts store store.AutomationGetter } @@ -48,9 +48,7 @@ func (opts *opsManagerAutomationShowOpts) Run() error { // mongocli ops-manager automation show [--projectId projectId] func OpsManagerAutomationShowBuilder() *cobra.Command { - opts := &opsManagerAutomationShowOpts{ - globalOpts: newGlobalOpts(), - } + opts := &opsManagerAutomationShowOpts{} cmd := &cobra.Command{ Use: "show", Args: cobra.NoArgs, diff --git a/internal/cli/ops_manager_automation_show_test.go b/internal/cli/ops_manager_automation_show_test.go index 491537caf0..678d919532 100644 --- a/internal/cli/ops_manager_automation_show_test.go +++ b/internal/cli/ops_manager_automation_show_test.go @@ -31,8 +31,7 @@ func TestOpsManagerAutomationShowOpts_Run(t *testing.T) { expected := fixtures.AutomationConfig() opts := &opsManagerAutomationShowOpts{ - globalOpts: newGlobalOpts(), - store: mockStore, + store: mockStore, } mockStore. diff --git a/internal/cli/ops_manager_automation_status.go b/internal/cli/ops_manager_automation_status.go index 141aa4561c..4e726d6439 100644 --- a/internal/cli/ops_manager_automation_status.go +++ b/internal/cli/ops_manager_automation_status.go @@ -24,7 +24,7 @@ import ( ) type opsManagerAutomationStatusOpts struct { - *globalOpts + globalOpts store store.AutomationStatusGetter } @@ -49,9 +49,7 @@ func (opts *opsManagerAutomationStatusOpts) Run() error { // mongocli ops-manager automation status [--projectId projectId] func OpsManagerAutomationStatusBuilder() *cobra.Command { - opts := &opsManagerAutomationStatusOpts{ - globalOpts: newGlobalOpts(), - } + opts := &opsManagerAutomationStatusOpts{} cmd := &cobra.Command{ Use: "status", Short: description.ShowAutomationStatus, diff --git a/internal/cli/ops_manager_automation_status_test.go b/internal/cli/ops_manager_automation_status_test.go index 4e7dd21c96..976ccb7f21 100644 --- a/internal/cli/ops_manager_automation_status_test.go +++ b/internal/cli/ops_manager_automation_status_test.go @@ -31,8 +31,7 @@ func TestOpsManagerAutomationStatus_Run(t *testing.T) { expected := fixtures.AutomationStatus() opts := &opsManagerAutomationStatusOpts{ - globalOpts: newGlobalOpts(), - store: mockStore, + store: mockStore, } mockStore. diff --git a/internal/cli/cloud_manager_clusters.go b/internal/cli/ops_manager_clusters.go similarity index 65% rename from internal/cli/cloud_manager_clusters.go rename to internal/cli/ops_manager_clusters.go index 59b0a22af1..7512475c39 100644 --- a/internal/cli/cloud_manager_clusters.go +++ b/internal/cli/ops_manager_clusters.go @@ -19,20 +19,20 @@ import ( "github.com/spf13/cobra" ) -func CloudManagerClustersBuilder() *cobra.Command { +func OpsManagerClustersBuilder() *cobra.Command { cmd := &cobra.Command{ Use: "clusters", Aliases: []string{"cluster"}, Short: description.Clusters, } - cmd.AddCommand(CloudManagerClustersListBuilder()) - cmd.AddCommand(CloudManagerClustersDescribeBuilder()) - cmd.AddCommand(CloudManagerClustersCreateBuilder()) - cmd.AddCommand(CloudManagerClustersShutdownBuilder()) - cmd.AddCommand(CloudManagerClustersStartupBuilder()) - cmd.AddCommand(CloudManagerClustersUpdateBuilder()) - cmd.AddCommand(CloudManagerClustersApplyBuilder()) + cmd.AddCommand(OpsManagerClustersListBuilder()) + cmd.AddCommand(OpsManagerManagerClustersDescribeBuilder()) + cmd.AddCommand(OpsManagerManagerClustersCreateBuilder()) + cmd.AddCommand(OpsManagerClustersShutdownBuilder()) + cmd.AddCommand(OpsManagerClustersStartupBuilder()) + cmd.AddCommand(OpsManagerClustersUpdateBuilder()) + cmd.AddCommand(OpsManagerClustersApplyBuilder()) return cmd } diff --git a/internal/cli/cloud_manager_clusters_apply.go b/internal/cli/ops_manager_clusters_apply.go similarity index 88% rename from internal/cli/cloud_manager_clusters_apply.go rename to internal/cli/ops_manager_clusters_apply.go index 9397a2e2ab..9d82e35b9f 100644 --- a/internal/cli/cloud_manager_clusters_apply.go +++ b/internal/cli/ops_manager_clusters_apply.go @@ -29,14 +29,14 @@ import ( "github.com/spf13/cobra" ) -type cmClustersApplyOpts struct { - *globalOpts +type opsManagerClustersApplyOpts struct { + globalOpts filename string fs afero.Fs store store.AutomationPatcher } -func (opts *cmClustersApplyOpts) init() error { +func (opts *opsManagerClustersApplyOpts) init() error { if opts.ProjectID() == "" { return errMissingProjectID } @@ -46,7 +46,7 @@ func (opts *cmClustersApplyOpts) init() error { return err } -func (opts *cmClustersApplyOpts) Run() error { +func (opts *opsManagerClustersApplyOpts) Run() error { newConfig := new(convert.ClusterConfig) err := file.Load(opts.fs, opts.filename, newConfig) if err != nil { @@ -74,10 +74,9 @@ func (opts *cmClustersApplyOpts) Run() error { } // mongocli cloud-manager cluster(s) apply --projectId projectId --file myfile.yaml -func CloudManagerClustersApplyBuilder() *cobra.Command { - opts := &cmClustersApplyOpts{ - globalOpts: newGlobalOpts(), - fs: afero.NewOsFs(), +func OpsManagerClustersApplyBuilder() *cobra.Command { + opts := &opsManagerClustersApplyOpts{ + fs: afero.NewOsFs(), } cmd := &cobra.Command{ Use: "apply", diff --git a/internal/cli/cloud_manager_clusters_apply_test.go b/internal/cli/ops_manager_clusters_apply_test.go similarity index 93% rename from internal/cli/cloud_manager_clusters_apply_test.go rename to internal/cli/ops_manager_clusters_apply_test.go index 22df025a69..114f8eed78 100644 --- a/internal/cli/cloud_manager_clusters_apply_test.go +++ b/internal/cli/ops_manager_clusters_apply_test.go @@ -58,11 +58,10 @@ processes: port: 29030` fileName := "test.yml" _ = afero.WriteFile(appFS, fileName, []byte(fileYML), 0600) - createOpts := &cmClustersApplyOpts{ - globalOpts: newGlobalOpts(), - store: mockStore, - fs: appFS, - filename: fileName, + createOpts := &opsManagerClustersApplyOpts{ + store: mockStore, + fs: appFS, + filename: fileName, } mockStore. diff --git a/internal/cli/cloud_manager_clusters_create.go b/internal/cli/ops_manager_clusters_create.go similarity index 89% rename from internal/cli/cloud_manager_clusters_create.go rename to internal/cli/ops_manager_clusters_create.go index 0ac0952fdd..e547670e57 100644 --- a/internal/cli/cloud_manager_clusters_create.go +++ b/internal/cli/ops_manager_clusters_create.go @@ -30,14 +30,14 @@ import ( "github.com/spf13/cobra" ) -type cmClustersCreateOpts struct { - *globalOpts +type opsManagerClustersCreateOpts struct { + globalOpts filename string fs afero.Fs store store.AutomationPatcher } -func (opts *cmClustersCreateOpts) init() error { +func (opts *opsManagerClustersCreateOpts) init() error { if opts.ProjectID() == "" { return errMissingProjectID } @@ -47,7 +47,7 @@ func (opts *cmClustersCreateOpts) init() error { return err } -func (opts *cmClustersCreateOpts) Run() error { +func (opts *opsManagerClustersCreateOpts) Run() error { newConfig := new(convert.ClusterConfig) err := file.Load(opts.fs, opts.filename, newConfig) if err != nil { @@ -79,10 +79,9 @@ func (opts *cmClustersCreateOpts) Run() error { } // mongocli cloud-manager cluster(s) create --projectId projectId --file myfile.yaml -func CloudManagerClustersCreateBuilder() *cobra.Command { - opts := &cmClustersCreateOpts{ - globalOpts: newGlobalOpts(), - fs: afero.NewOsFs(), +func OpsManagerManagerClustersCreateBuilder() *cobra.Command { + opts := &opsManagerClustersCreateOpts{ + fs: afero.NewOsFs(), } cmd := &cobra.Command{ Use: "create", diff --git a/internal/cli/cloud_manager_clusters_create_test.go b/internal/cli/ops_manager_clusters_create_test.go similarity index 93% rename from internal/cli/cloud_manager_clusters_create_test.go rename to internal/cli/ops_manager_clusters_create_test.go index 21de7f706a..fdbf7f7e7c 100644 --- a/internal/cli/cloud_manager_clusters_create_test.go +++ b/internal/cli/ops_manager_clusters_create_test.go @@ -59,11 +59,10 @@ processes: fileName := "test.yml" _ = afero.WriteFile(appFS, fileName, []byte(fileYML), 0600) - createOpts := &cmClustersCreateOpts{ - globalOpts: newGlobalOpts(), - store: mockStore, - fs: appFS, - filename: fileName, + createOpts := &opsManagerClustersCreateOpts{ + store: mockStore, + fs: appFS, + filename: fileName, } mockStore. diff --git a/internal/cli/cloud_manager_clusters_describe.go b/internal/cli/ops_manager_clusters_describe.go similarity index 87% rename from internal/cli/cloud_manager_clusters_describe.go rename to internal/cli/ops_manager_clusters_describe.go index 6eceba7b8f..518db023ff 100644 --- a/internal/cli/cloud_manager_clusters_describe.go +++ b/internal/cli/ops_manager_clusters_describe.go @@ -26,13 +26,13 @@ import ( "github.com/spf13/cobra" ) -type cmClustersDescribeOpts struct { - *globalOpts +type opsManagerClustersDescribeOpts struct { + globalOpts name string store store.AutomationGetter } -func (opts *cmClustersDescribeOpts) init() error { +func (opts *opsManagerClustersDescribeOpts) init() error { if opts.ProjectID() == "" { return errMissingProjectID } @@ -42,7 +42,7 @@ func (opts *cmClustersDescribeOpts) init() error { return err } -func (opts *cmClustersDescribeOpts) Run() error { +func (opts *opsManagerClustersDescribeOpts) Run() error { result, err := opts.store.GetAutomationConfig(opts.ProjectID()) if err != nil { @@ -60,10 +60,8 @@ func (opts *cmClustersDescribeOpts) Run() error { } // mongocli cloud-manager cluster(s) describe [name] --projectId projectId -func CloudManagerClustersDescribeBuilder() *cobra.Command { - opts := &cmClustersDescribeOpts{ - globalOpts: newGlobalOpts(), - } +func OpsManagerManagerClustersDescribeBuilder() *cobra.Command { + opts := &opsManagerClustersDescribeOpts{} cmd := &cobra.Command{ Use: "describe [name]", Short: description.DescribeCluster, diff --git a/internal/cli/cloud_manager_clusters_describe_test.go b/internal/cli/ops_manager_clusters_describe_test.go similarity index 90% rename from internal/cli/cloud_manager_clusters_describe_test.go rename to internal/cli/ops_manager_clusters_describe_test.go index cf7937895e..7befcb749c 100644 --- a/internal/cli/cloud_manager_clusters_describe_test.go +++ b/internal/cli/ops_manager_clusters_describe_test.go @@ -30,10 +30,9 @@ func TestCloudManagerClustersDescribe_Run(t *testing.T) { expected := fixtures.AutomationConfig() - descOpts := &cmClustersDescribeOpts{ - globalOpts: newGlobalOpts(), - store: mockStore, - name: "myReplicaSet", + descOpts := &opsManagerClustersDescribeOpts{ + store: mockStore, + name: "myReplicaSet", } mockStore. diff --git a/internal/cli/cloud_manager_clusters_list.go b/internal/cli/ops_manager_clusters_list.go similarity index 81% rename from internal/cli/cloud_manager_clusters_list.go rename to internal/cli/ops_manager_clusters_list.go index bd8daacb68..ba7adde166 100644 --- a/internal/cli/cloud_manager_clusters_list.go +++ b/internal/cli/ops_manager_clusters_list.go @@ -25,19 +25,19 @@ import ( "github.com/spf13/cobra" ) -type cloudManagerClustersListOpts struct { - *globalOpts +type opsManagerClustersListOpts struct { + globalOpts store store.CloudManagerClustersLister } -func (opts *cloudManagerClustersListOpts) init() error { +func (opts *opsManagerClustersListOpts) init() error { var err error opts.store, err = store.New() return err } -func (opts *cloudManagerClustersListOpts) Run() error { - result, err := cloudManagerClustersListRun(opts) +func (opts *opsManagerClustersListOpts) Run() error { + result, err := opts.cloudManagerClustersListRun() if err != nil { return err @@ -46,7 +46,7 @@ func (opts *cloudManagerClustersListOpts) Run() error { return json.PrettyPrint(result) } -func cloudManagerClustersListRun(opts *cloudManagerClustersListOpts) (interface{}, error) { +func (opts *opsManagerClustersListOpts) cloudManagerClustersListRun() (interface{}, error) { var result interface{} var err error @@ -62,10 +62,8 @@ func cloudManagerClustersListRun(opts *cloudManagerClustersListOpts) (interface{ } // mongocli cloud-manager cluster(s) list --projectId projectId -func CloudManagerClustersListBuilder() *cobra.Command { - opts := &cloudManagerClustersListOpts{ - globalOpts: newGlobalOpts(), - } +func OpsManagerClustersListBuilder() *cobra.Command { + opts := &opsManagerClustersListOpts{} cmd := &cobra.Command{ Use: "list", Aliases: []string{"ls"}, diff --git a/internal/cli/cloud_manager_clusters_list_test.go b/internal/cli/ops_manager_clusters_list_test.go similarity index 88% rename from internal/cli/cloud_manager_clusters_list_test.go rename to internal/cli/ops_manager_clusters_list_test.go index e31cdf2c42..7d638a6f84 100644 --- a/internal/cli/cloud_manager_clusters_list_test.go +++ b/internal/cli/ops_manager_clusters_list_test.go @@ -32,9 +32,8 @@ func TestCloudManagerClustersList_Run(t *testing.T) { t.Run("ProjectID is given", func(t *testing.T) { expected := fixtures.AutomationConfig() - listOpts := &cloudManagerClustersListOpts{ - globalOpts: newGlobalOpts(), - store: mockStore, + listOpts := &opsManagerClustersListOpts{ + store: mockStore, } listOpts.projectID = "1" @@ -60,9 +59,8 @@ func TestCloudManagerClustersList_Run(t *testing.T) { Return(expected, nil). Times(1) - listOpts := &cloudManagerClustersListOpts{ - globalOpts: newGlobalOpts(), - store: mockStore, + listOpts := &opsManagerClustersListOpts{ + store: mockStore, } err := listOpts.Run() diff --git a/internal/cli/cloud_manager_clusters_shutdown.go b/internal/cli/ops_manager_clusters_shutdown.go similarity index 88% rename from internal/cli/cloud_manager_clusters_shutdown.go rename to internal/cli/ops_manager_clusters_shutdown.go index 7c59de9c6c..8653046c73 100644 --- a/internal/cli/cloud_manager_clusters_shutdown.go +++ b/internal/cli/ops_manager_clusters_shutdown.go @@ -29,14 +29,14 @@ import ( "github.com/spf13/cobra" ) -type cmClustersShutdownOpts struct { - *globalOpts +type opsManagerClustersShutdownOpts struct { + globalOpts name string confirm bool store store.AutomationPatcher } -func (opts *cmClustersShutdownOpts) init() error { +func (opts *opsManagerClustersShutdownOpts) init() error { if opts.ProjectID() == "" { return errMissingProjectID } @@ -46,7 +46,7 @@ func (opts *cmClustersShutdownOpts) init() error { return err } -func (opts *cmClustersShutdownOpts) Run() error { +func (opts *opsManagerClustersShutdownOpts) Run() error { if !opts.confirm { return nil } @@ -71,7 +71,7 @@ func (opts *cmClustersShutdownOpts) Run() error { return nil } -func (opts *cmClustersShutdownOpts) Confirm() error { +func (opts *opsManagerClustersShutdownOpts) Confirm() error { if opts.confirm { return nil } @@ -82,10 +82,8 @@ func (opts *cmClustersShutdownOpts) Confirm() error { } // mongocli cloud-manager cluster(s) shutdown [name] --projectId projectId [--force] -func CloudManagerClustersShutdownBuilder() *cobra.Command { - opts := &cmClustersShutdownOpts{ - globalOpts: newGlobalOpts(), - } +func OpsManagerClustersShutdownBuilder() *cobra.Command { + opts := &opsManagerClustersShutdownOpts{} cmd := &cobra.Command{ Use: "shutdown [name]", Short: description.ShutdownOMCluster, diff --git a/internal/cli/cloud_manager_clusters_shutdown_test.go b/internal/cli/ops_manager_clusters_shutdown_test.go similarity index 89% rename from internal/cli/cloud_manager_clusters_shutdown_test.go rename to internal/cli/ops_manager_clusters_shutdown_test.go index 814889ccfb..471d7f22b4 100644 --- a/internal/cli/cloud_manager_clusters_shutdown_test.go +++ b/internal/cli/ops_manager_clusters_shutdown_test.go @@ -30,11 +30,10 @@ func TestCloudManagerClustersShutdown_Run(t *testing.T) { expected := fixtures.AutomationConfig() - createOpts := &cmClustersShutdownOpts{ - globalOpts: newGlobalOpts(), - store: mockStore, - confirm: true, - name: "myReplicaSet", + createOpts := &opsManagerClustersShutdownOpts{ + store: mockStore, + confirm: true, + name: "myReplicaSet", } mockStore. diff --git a/internal/cli/cloud_manager_clusters_startup.go b/internal/cli/ops_manager_clusters_startup.go similarity index 88% rename from internal/cli/cloud_manager_clusters_startup.go rename to internal/cli/ops_manager_clusters_startup.go index cf6e653ccd..94bc2edb41 100644 --- a/internal/cli/cloud_manager_clusters_startup.go +++ b/internal/cli/ops_manager_clusters_startup.go @@ -29,14 +29,14 @@ import ( "github.com/spf13/cobra" ) -type cmClustersStartupOpts struct { - *globalOpts +type opsManagerClustersStartupOpts struct { + globalOpts name string confirm bool store store.AutomationPatcher } -func (opts *cmClustersStartupOpts) init() error { +func (opts *opsManagerClustersStartupOpts) init() error { if opts.ProjectID() == "" { return errMissingProjectID } @@ -46,7 +46,7 @@ func (opts *cmClustersStartupOpts) init() error { return err } -func (opts *cmClustersStartupOpts) Run() error { +func (opts *opsManagerClustersStartupOpts) Run() error { if !opts.confirm { return nil } @@ -71,7 +71,7 @@ func (opts *cmClustersStartupOpts) Run() error { return nil } -func (opts *cmClustersStartupOpts) Confirm() error { +func (opts *opsManagerClustersStartupOpts) Confirm() error { if opts.confirm { return nil } @@ -82,10 +82,8 @@ func (opts *cmClustersStartupOpts) Confirm() error { } // mongocli cloud-manager cluster(s) startup [name] --projectId projectId [--force] -func CloudManagerClustersStartupBuilder() *cobra.Command { - opts := &cmClustersStartupOpts{ - globalOpts: newGlobalOpts(), - } +func OpsManagerClustersStartupBuilder() *cobra.Command { + opts := &opsManagerClustersStartupOpts{} cmd := &cobra.Command{ Use: "startup [name]", Short: description.StartUpOMCluster, diff --git a/internal/cli/cloud_manager_clusters_startup_test.go b/internal/cli/ops_manager_clusters_startup_test.go similarity index 89% rename from internal/cli/cloud_manager_clusters_startup_test.go rename to internal/cli/ops_manager_clusters_startup_test.go index f9871bfd01..fe4089c93b 100644 --- a/internal/cli/cloud_manager_clusters_startup_test.go +++ b/internal/cli/ops_manager_clusters_startup_test.go @@ -30,11 +30,10 @@ func TestCloudManagerClustersStartup_Run(t *testing.T) { expected := fixtures.AutomationConfig() - createOpts := &cmClustersStartupOpts{ - globalOpts: newGlobalOpts(), - store: mockStore, - confirm: true, - name: "myReplicaSet", + createOpts := &opsManagerClustersStartupOpts{ + store: mockStore, + confirm: true, + name: "myReplicaSet", } mockStore. diff --git a/internal/cli/cloud_manager_clusters_update.go b/internal/cli/ops_manager_clusters_update.go similarity index 89% rename from internal/cli/cloud_manager_clusters_update.go rename to internal/cli/ops_manager_clusters_update.go index 491fdbe2ca..f092e3122b 100644 --- a/internal/cli/cloud_manager_clusters_update.go +++ b/internal/cli/ops_manager_clusters_update.go @@ -30,14 +30,14 @@ import ( "github.com/spf13/cobra" ) -type cmClustersUpdateOpts struct { - *globalOpts +type opsManagerClustersUpdateOpts struct { + globalOpts filename string fs afero.Fs store store.AutomationPatcher } -func (opts *cmClustersUpdateOpts) init() error { +func (opts *opsManagerClustersUpdateOpts) init() error { if opts.ProjectID() == "" { return errMissingProjectID } @@ -47,7 +47,7 @@ func (opts *cmClustersUpdateOpts) init() error { return err } -func (opts *cmClustersUpdateOpts) Run() error { +func (opts *opsManagerClustersUpdateOpts) Run() error { newConfig := new(convert.ClusterConfig) err := file.Load(opts.fs, opts.filename, newConfig) if err != nil { @@ -79,10 +79,9 @@ func (opts *cmClustersUpdateOpts) Run() error { } // mongocli cloud-manager cluster(s) update --projectId projectId --file myfile.yaml -func CloudManagerClustersUpdateBuilder() *cobra.Command { - opts := &cmClustersUpdateOpts{ - globalOpts: newGlobalOpts(), - fs: afero.NewOsFs(), +func OpsManagerClustersUpdateBuilder() *cobra.Command { + opts := &opsManagerClustersUpdateOpts{ + fs: afero.NewOsFs(), } cmd := &cobra.Command{ Use: "update", diff --git a/internal/cli/cloud_manager_clusters_update_test.go b/internal/cli/ops_manager_clusters_update_test.go similarity index 93% rename from internal/cli/cloud_manager_clusters_update_test.go rename to internal/cli/ops_manager_clusters_update_test.go index cce917b3f7..9f01992750 100644 --- a/internal/cli/cloud_manager_clusters_update_test.go +++ b/internal/cli/ops_manager_clusters_update_test.go @@ -58,11 +58,10 @@ processes: port: 29030` fileName := "test.yml" _ = afero.WriteFile(appFS, fileName, []byte(fileYML), 0600) - createOpts := &cmClustersUpdateOpts{ - globalOpts: newGlobalOpts(), - store: mockStore, - fs: appFS, - filename: fileName, + createOpts := &opsManagerClustersUpdateOpts{ + store: mockStore, + fs: appFS, + filename: fileName, } mockStore. diff --git a/internal/cli/ops_manager_dbusers_create.go b/internal/cli/ops_manager_dbusers_create.go index 2d19955ba6..2be8b1bee4 100644 --- a/internal/cli/ops_manager_dbusers_create.go +++ b/internal/cli/ops_manager_dbusers_create.go @@ -33,7 +33,7 @@ import ( const scransha1 = "SCRAM-SHA-1" type opsManagerDBUsersCreateOpts struct { - *globalOpts + globalOpts username string password string authDB string @@ -93,9 +93,7 @@ func (opts *opsManagerDBUsersCreateOpts) Prompt() error { // mongocli atlas dbuser(s) create --username username --password password --role roleName@dbName [--projectId projectId] func OpsManagerDBUsersCreateBuilder() *cobra.Command { - opts := &opsManagerDBUsersCreateOpts{ - globalOpts: newGlobalOpts(), - } + opts := &opsManagerDBUsersCreateOpts{} cmd := &cobra.Command{ Use: "create", Short: description.CreateDBUser, diff --git a/internal/cli/ops_manager_dbusers_create_test.go b/internal/cli/ops_manager_dbusers_create_test.go index d028d959d8..a51a5de24b 100644 --- a/internal/cli/ops_manager_dbusers_create_test.go +++ b/internal/cli/ops_manager_dbusers_create_test.go @@ -31,11 +31,10 @@ func TestOpsManagerDBUserCreate_Run(t *testing.T) { expected := fixtures.AutomationConfig() createOpts := &opsManagerDBUsersCreateOpts{ - globalOpts: newGlobalOpts(), - username: "ProjectBar", - password: "US", - roles: []string{"admin@admin"}, - store: mockStore, + username: "ProjectBar", + password: "US", + roles: []string{"admin@admin"}, + store: mockStore, } mockStore. diff --git a/internal/cli/ops_manager_dbusers_delete.go b/internal/cli/ops_manager_dbusers_delete.go index eb9b69fc01..9f2c590107 100644 --- a/internal/cli/ops_manager_dbusers_delete.go +++ b/internal/cli/ops_manager_dbusers_delete.go @@ -29,8 +29,8 @@ import ( ) type opsManagerDBUsersDeleteOpts struct { - *globalOpts - *deleteOpts + globalOpts + deleteOpts authDB string store store.AutomationPatcher } @@ -68,8 +68,7 @@ func (opts *opsManagerDBUsersDeleteOpts) Run() error { // mongocli atlas dbuser(s) delete [--projectId projectId] [--force] func OpsManagerDBUsersDeleteBuilder() *cobra.Command { opts := &opsManagerDBUsersDeleteOpts{ - globalOpts: newGlobalOpts(), - deleteOpts: &deleteOpts{ + deleteOpts: deleteOpts{ successMessage: "DB user '%s' deleted\n", failMessage: "DB user not deleted", }, diff --git a/internal/cli/ops_manager_dbusers_delete_test.go b/internal/cli/ops_manager_dbusers_delete_test.go index cb3638367d..1af1958a74 100644 --- a/internal/cli/ops_manager_dbusers_delete_test.go +++ b/internal/cli/ops_manager_dbusers_delete_test.go @@ -31,8 +31,7 @@ func TestOpsManagerDBUserDelete_Run(t *testing.T) { expected := fixtures.AutomationConfigWithMongoDBUsers() createOpts := &opsManagerDBUsersDeleteOpts{ - globalOpts: newGlobalOpts(), - deleteOpts: &deleteOpts{ + deleteOpts: deleteOpts{ confirm: true, entry: "test", successMessage: "DB user '%s' deleted\n", diff --git a/internal/cli/ops_manager_dbusers_list.go b/internal/cli/ops_manager_dbusers_list.go index 6c31834bab..b57bee3228 100644 --- a/internal/cli/ops_manager_dbusers_list.go +++ b/internal/cli/ops_manager_dbusers_list.go @@ -24,7 +24,7 @@ import ( ) type opsManagerDBUsersListOpts struct { - *globalOpts + globalOpts store store.AutomationGetter } @@ -50,9 +50,7 @@ func (opts *opsManagerDBUsersListOpts) Run() error { // mongocli om|cm dbuser(s) list [--projectId projectId] func OpsManagerDBUsersListBuilder() *cobra.Command { - opts := &opsManagerDBUsersListOpts{ - globalOpts: newGlobalOpts(), - } + opts := &opsManagerDBUsersListOpts{} cmd := &cobra.Command{ Use: "list", Short: description.ListDBUsers, diff --git a/internal/cli/ops_manager_dbusers_list_test.go b/internal/cli/ops_manager_dbusers_list_test.go index 5b1c9e6a84..826c06a365 100644 --- a/internal/cli/ops_manager_dbusers_list_test.go +++ b/internal/cli/ops_manager_dbusers_list_test.go @@ -31,8 +31,7 @@ func TestOpsManagerDBUserList_Run(t *testing.T) { expected := fixtures.AutomationConfig() createOpts := &opsManagerDBUsersListOpts{ - globalOpts: newGlobalOpts(), - store: mockStore, + store: mockStore, } mockStore. diff --git a/internal/cli/ops_manager_measurements_process.go b/internal/cli/ops_manager_measurements_process.go index cde142c54b..a512afe22a 100644 --- a/internal/cli/ops_manager_measurements_process.go +++ b/internal/cli/ops_manager_measurements_process.go @@ -15,7 +15,6 @@ package cli import ( - atlas "github.com/mongodb/go-client-mongodb-atlas/mongodbatlas" "github.com/mongodb/mongocli/internal/description" "github.com/mongodb/mongocli/internal/flags" "github.com/mongodb/mongocli/internal/json" @@ -25,16 +24,10 @@ import ( ) type OpsManagerMeasurementsProcessOpts struct { - *globalOpts - pageNum int - itemsPerPage int - hostID string - granularity string - period string - start string - end string - measurementType string - store store.HostMeasurementLister + globalOpts + measurementsOpts + hostID string + store store.HostMeasurementLister } func (opts *OpsManagerMeasurementsProcessOpts) init() error { @@ -58,25 +51,9 @@ func (opts *OpsManagerMeasurementsProcessOpts) Run() error { return json.PrettyPrint(result) } -func (opts *OpsManagerMeasurementsProcessOpts) newProcessMeasurementListOptions() *atlas.ProcessMeasurementListOptions { - return &atlas.ProcessMeasurementListOptions{ - ListOptions: &atlas.ListOptions{ - PageNum: opts.pageNum, - ItemsPerPage: opts.itemsPerPage, - }, - Granularity: opts.granularity, - Period: opts.period, - Start: opts.start, - End: opts.end, - M: opts.measurementType, - } -} - // mongocli om|cm measurements process(es) hostId [--granularity granularity] [--period period] [--start start] [--end end] [--type type][--projectId projectId] func OpsManagerMeasurementsProcessBuilder() *cobra.Command { - opts := &OpsManagerMeasurementsProcessOpts{ - globalOpts: newGlobalOpts(), - } + opts := &OpsManagerMeasurementsProcessOpts{} cmd := &cobra.Command{ Use: "process", Short: description.ProcessMeasurements, diff --git a/internal/cli/ops_manager_measurements_process_test.go b/internal/cli/ops_manager_measurements_process_test.go index 40a3360094..5f5224ab74 100644 --- a/internal/cli/ops_manager_measurements_process_test.go +++ b/internal/cli/ops_manager_measurements_process_test.go @@ -30,12 +30,12 @@ func TestOpsManagerMeasurementsProcess_Run(t *testing.T) { expected := fixtures.ProcessMeasurements() listOpts := &OpsManagerMeasurementsProcessOpts{ - globalOpts: newGlobalOpts(), - hostID: "hard-00-00.mongodb.net", - granularity: "PT1M", - period: "PT1M", - store: mockStore, + hostID: "hard-00-00.mongodb.net", + + store: mockStore, } + listOpts.granularity = "PT1M" + listOpts.period = "PT1M" opts := listOpts.newProcessMeasurementListOptions() mockStore. diff --git a/internal/cli/ops_manager_security_enable.go b/internal/cli/ops_manager_security_enable.go index a770561ed0..a82fd86b49 100644 --- a/internal/cli/ops_manager_security_enable.go +++ b/internal/cli/ops_manager_security_enable.go @@ -34,7 +34,7 @@ const ( ) type opsManagerSecurityEnableOpts struct { - *globalOpts + globalOpts mechanisms []string store store.AutomationPatcher } @@ -69,9 +69,7 @@ func (opts *opsManagerSecurityEnableOpts) Run() error { // mongocli ops-manager security enable[MONGODB-CR|SCRAM-SHA-256] [--projectId projectId] func OpsManagerSecurityEnableBuilder() *cobra.Command { - opts := &opsManagerSecurityEnableOpts{ - globalOpts: newGlobalOpts(), - } + opts := &opsManagerSecurityEnableOpts{} cmd := &cobra.Command{ Use: fmt.Sprintf("enable [%s|%s]", cr, sha256), Short: description.EnableSecurity, diff --git a/internal/cli/ops_manager_security_enable_test.go b/internal/cli/ops_manager_security_enable_test.go index 98884cfd64..56cdc38516 100644 --- a/internal/cli/ops_manager_security_enable_test.go +++ b/internal/cli/ops_manager_security_enable_test.go @@ -31,7 +31,6 @@ func TestOpsManagerSecurityEnableOpts_Run(t *testing.T) { expected := fixtures.AutomationConfig() createOpts := &opsManagerSecurityEnableOpts{ - globalOpts: newGlobalOpts(), mechanisms: []string{"something"}, store: mockStore, } diff --git a/internal/cli/ops_manager_servers_list.go b/internal/cli/ops_manager_servers_list.go index 5f3bbef4a3..7c742f0e52 100644 --- a/internal/cli/ops_manager_servers_list.go +++ b/internal/cli/ops_manager_servers_list.go @@ -26,18 +26,18 @@ const ( agentType = "AUTOMATION" ) -type OpsManagerServersListOpts struct { - *globalOpts +type opsManagerServersListOpts struct { + globalOpts store store.AgentLister } -func (opts *OpsManagerServersListOpts) init() error { +func (opts *opsManagerServersListOpts) init() error { var err error opts.store, err = store.New() return err } -func (opts *OpsManagerServersListOpts) Run() error { +func (opts *opsManagerServersListOpts) Run() error { servers, err := opts.store.Agents(opts.projectID, agentType) if err != nil { @@ -49,9 +49,7 @@ func (opts *OpsManagerServersListOpts) Run() error { // mongocli om server(s) list [--projectId projectId] func OpsManagerAgentsListBuilder() *cobra.Command { - opts := &OpsManagerServersListOpts{ - globalOpts: newGlobalOpts(), - } + opts := &opsManagerServersListOpts{} cmd := &cobra.Command{ Use: "list", Aliases: []string{"ls"}, diff --git a/internal/cli/ops_manager_servers_list_test.go b/internal/cli/ops_manager_servers_list_test.go index 810308060f..ca69f04450 100644 --- a/internal/cli/ops_manager_servers_list_test.go +++ b/internal/cli/ops_manager_servers_list_test.go @@ -31,12 +31,10 @@ func TestOpsManagerAgentsList_Run(t *testing.T) { expected := fixtures.Agents() - listOpts := OpsManagerServersListOpts{ - globalOpts: &globalOpts{ - projectID: "1", - }, + listOpts := opsManagerServersListOpts{ store: mockStore, } + listOpts.projectID = "1" mockStore. EXPECT().