Skip to content

CLOUDP-59635: Embedding pagination into a struct to favour reuse #95

New issue

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

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

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions internal/cli/atlas_alerts_acknowledge.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
)

type atlasAlertsAcknowledgeOpts struct {
*globalOpts
globalOpts
alertID string
until string
comment string
Expand Down Expand Up @@ -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,
Expand Down
9 changes: 4 additions & 5 deletions internal/cli/atlas_alerts_acknowledge_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
9 changes: 3 additions & 6 deletions internal/cli/atlas_alerts_config_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ const (
)

type atlasAlertsConfigCreateOpts struct {
*globalOpts
*atlasAlertsConfigOpts
globalOpts
atlasAlertsConfigOpts
store store.AlertConfigurationCreator
}

Expand Down Expand Up @@ -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,
Expand Down
3 changes: 1 addition & 2 deletions internal/cli/atlas_alerts_config_create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
14 changes: 5 additions & 9 deletions internal/cli/atlas_alerts_config_delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import (
)

type atlasAlertsConfigDeleteOpts struct {
*globalOpts
*deleteOpts
globalOpts
deleteOpts
store store.AlertConfigurationDeleter
}

Expand All @@ -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,
Expand Down
9 changes: 3 additions & 6 deletions internal/cli/atlas_alerts_config_delete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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().
Expand Down
19 changes: 4 additions & 15 deletions internal/cli/atlas_alerts_config_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 {
Expand All @@ -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,
Expand Down
3 changes: 1 addition & 2 deletions internal/cli/atlas_alerts_config_list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ func TestAtlasAlertsConfigList_Run(t *testing.T) {
expected := fixtures.AlertConfigs()

listOpts := &atlasAlertsConfigListOpts{
globalOpts: newGlobalOpts(),
store: mockStore,
store: mockStore,
}

mockStore.
Expand Down
9 changes: 3 additions & 6 deletions internal/cli/atlas_alerts_config_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ import (
)

type atlasAlertsConfigUpdateOpts struct {
*globalOpts
*atlasAlertsConfigOpts
globalOpts
atlasAlertsConfigOpts
store store.AlertConfigurationUpdater
alertID string
}
Expand Down Expand Up @@ -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,
Expand Down
3 changes: 1 addition & 2 deletions internal/cli/atlas_alerts_config_update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 2 additions & 4 deletions internal/cli/atlas_alerts_describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
)

type atlasAlertsDescribeOpts struct {
*globalOpts
globalOpts
alertID string
store store.AlertDescriber
}
Expand All @@ -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,
Expand Down
5 changes: 2 additions & 3 deletions internal/cli/atlas_alerts_describe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
26 changes: 11 additions & 15 deletions internal/cli/atlas_alerts_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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,
Expand Down
5 changes: 2 additions & 3 deletions internal/cli/atlas_alerts_list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
21 changes: 5 additions & 16 deletions internal/cli/atlas_backups_checkpoints_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 {
Expand All @@ -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"},
Expand Down
1 change: 0 additions & 1 deletion internal/cli/atlas_backups_checkpoints_list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ func TestAtlasBackupsCheckpointsList_Run(t *testing.T) {
expected := fixtures.Checkpoints()

listOpts := &atlasBackupsCheckpointsListOpts{
globalOpts: newGlobalOpts(),
store: mockStore,
clusterName: "Cluster0",
}
Expand Down
21 changes: 5 additions & 16 deletions internal/cli/atlas_backups_restores_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 {
Expand All @@ -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"},
Expand Down
1 change: 0 additions & 1 deletion internal/cli/atlas_backups_restores_list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ func TestAtlasBackupsRestoresListOpts_Run(t *testing.T) {
expected := fixtures.ContinuousJobs()

listOpts := &atlasBackupsRestoresListOpts{
globalOpts: newGlobalOpts(),
store: mockStore,
clusterName: "Cluster0",
}
Expand Down
Loading