Skip to content

Commit ab69511

Browse files
CLOUDP-68271: simplified output for backups (#313)
1 parent 4f90371 commit ab69511

File tree

7 files changed

+60
-31
lines changed

7 files changed

+60
-31
lines changed

internal/cli/opsmanager/backup/checkpoints_list.go

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,19 @@ import (
2222
"github.com/mongodb/mongocli/internal/output"
2323
"github.com/mongodb/mongocli/internal/store"
2424
"github.com/mongodb/mongocli/internal/usage"
25+
"github.com/mongodb/mongocli/internal/validate"
2526
"github.com/spf13/cobra"
2627
)
2728

29+
const checkpointsTemplate = `ID TIMESTAMP{{range .Results}}
30+
{{.ID}} {{.Timestamp}}{{end}}
31+
`
32+
2833
type CheckpointsListOpts struct {
2934
cli.GlobalOpts
3035
cli.ListOpts
31-
clusterName string
32-
store store.CheckpointsLister
36+
clusterID string
37+
store store.CheckpointsLister
3338
}
3439

3540
func (opts *CheckpointsListOpts) initStore() error {
@@ -41,27 +46,30 @@ func (opts *CheckpointsListOpts) initStore() error {
4146
func (opts *CheckpointsListOpts) Run() error {
4247
listOpts := opts.NewListOptions()
4348

44-
r, err := opts.store.Checkpoints(opts.ConfigProjectID(), opts.clusterName, listOpts)
49+
r, err := opts.store.Checkpoints(opts.ConfigProjectID(), opts.clusterID, listOpts)
4550
if err != nil {
4651
return err
4752
}
4853

49-
return output.Print(config.Default(), "", r)
54+
return output.Print(config.Default(), checkpointsTemplate, r)
5055
}
5156

52-
// mongocli atlas backup(s) checkpoint(s) list <clusterName> [--projectId projectId]
57+
// mongocli atlas backup(s) checkpoint(s) list <clusterId> [--projectId projectId]
5358
func AtlasBackupsCheckpointsListBuilder() *cobra.Command {
5459
opts := new(CheckpointsListOpts)
5560
cmd := &cobra.Command{
56-
Use: "list <clusterName>",
61+
Use: "list <clusterId>",
5762
Aliases: []string{"ls"},
5863
Short: description.ListCheckpoints,
5964
Args: cobra.ExactArgs(1),
6065
PreRunE: func(cmd *cobra.Command, args []string) error {
66+
if err := validate.ObjectID(args[0]); err != nil {
67+
return err
68+
}
6169
return opts.PreRunE(opts.initStore)
6270
},
6371
RunE: func(cmd *cobra.Command, args []string) error {
64-
opts.clusterName = args[0]
72+
opts.clusterID = args[0]
6573
return opts.Run()
6674
},
6775
}

internal/cli/opsmanager/backup/checkpoints_list_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,16 @@ func TestCheckpointsList_Run(t *testing.T) {
3030
defer ctrl.Finish()
3131

3232
expected := &mongodbatlas.Checkpoints{}
33+
clusterID := "5ec2ac941271767f21cbaefd"
3334

3435
listOpts := &CheckpointsListOpts{
35-
store: mockStore,
36-
clusterName: "Cluster0",
36+
store: mockStore,
37+
clusterID: clusterID,
3738
}
3839

3940
mockStore.
4041
EXPECT().
41-
Checkpoints(listOpts.ProjectID, "Cluster0", listOpts.NewListOptions()).
42+
Checkpoints(listOpts.ProjectID, clusterID, listOpts.NewListOptions()).
4243
Return(expected, nil).
4344
Times(1)
4445

internal/cli/opsmanager/backup/restores_list.go

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,19 @@ import (
2222
"github.com/mongodb/mongocli/internal/output"
2323
"github.com/mongodb/mongocli/internal/store"
2424
"github.com/mongodb/mongocli/internal/usage"
25+
"github.com/mongodb/mongocli/internal/validate"
2526
"github.com/spf13/cobra"
2627
)
2728

29+
const restoresTemplate = `ID TIMESTAMP STATUS{{range .Results}}
30+
{{.ID}} {{.Timestamp.Date}} {{.StatusName}}{{end}}
31+
`
32+
2833
type RestoresListOpts struct {
2934
cli.GlobalOpts
3035
cli.ListOpts
31-
clusterName string
32-
store store.ContinuousJobLister
36+
clusterID string
37+
store store.ContinuousJobLister
3338
}
3439

3540
func (opts *RestoresListOpts) initStore() error {
@@ -40,27 +45,30 @@ func (opts *RestoresListOpts) initStore() error {
4045

4146
func (opts *RestoresListOpts) Run() error {
4247
listOpts := opts.NewListOptions()
43-
r, err := opts.store.ContinuousRestoreJobs(opts.ConfigProjectID(), opts.clusterName, listOpts)
48+
r, err := opts.store.ContinuousRestoreJobs(opts.ConfigProjectID(), opts.clusterID, listOpts)
4449
if err != nil {
4550
return err
4651
}
4752

48-
return output.Print(config.Default(), "", r)
53+
return output.Print(config.Default(), restoresTemplate, r)
4954
}
5055

51-
// mongocli atlas backup(s) restore(s) job(s) list <clusterName|clusterID> [--page N] [--limit N]
56+
// mongocli atlas backup(s) restore(s) job(s) list <clusterId> [--page N] [--limit N]
5257
func RestoresListBuilder() *cobra.Command {
5358
opts := new(RestoresListOpts)
5459
cmd := &cobra.Command{
55-
Use: "list <clusterName|clusterID>",
60+
Use: "list <clusterId>",
5661
Aliases: []string{"ls"},
5762
Short: description.ListRestores,
5863
Args: cobra.ExactArgs(1),
5964
PreRunE: func(cmd *cobra.Command, args []string) error {
6065
return opts.PreRunE(opts.initStore)
6166
},
6267
RunE: func(cmd *cobra.Command, args []string) error {
63-
opts.clusterName = args[0]
68+
if err := validate.ObjectID(args[0]); err != nil {
69+
return err
70+
}
71+
opts.clusterID = args[0]
6472

6573
return opts.Run()
6674
},

internal/cli/opsmanager/backup/restores_list_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,16 @@ func TestRestoresListOpts_Run(t *testing.T) {
3030
defer ctrl.Finish()
3131

3232
expected := &mongodbatlas.ContinuousJobs{}
33+
clusterID := "5ec2ac941271767f21cbaeff"
3334

3435
listOpts := &RestoresListOpts{
35-
store: mockStore,
36-
clusterName: "Cluster0",
36+
store: mockStore,
37+
clusterID: clusterID,
3738
}
3839

3940
mockStore.
4041
EXPECT().
41-
ContinuousRestoreJobs(listOpts.ProjectID, "Cluster0", listOpts.NewListOptions()).
42+
ContinuousRestoreJobs(listOpts.ProjectID, clusterID, listOpts.NewListOptions()).
4243
Return(expected, nil).
4344
Times(1)
4445

internal/cli/opsmanager/backup/restores_start.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ const (
3333
automatedRestore = "AUTOMATED_RESTORE"
3434
httpRestore = "HTTP"
3535
onlyFor = "'%s' can only be used with %s"
36+
createTemplate = `Created restore job(s):{{range .Results}} '{{.ID}}'{{end}}.
37+
`
3638
)
3739

3840
type RestoresStartOpts struct {
@@ -67,7 +69,7 @@ func (opts *RestoresStartOpts) Run() error {
6769
return err
6870
}
6971

70-
return output.Print(config.Default(), "", r)
72+
return output.Print(config.Default(), createTemplate, r)
7173
}
7274

7375
func (opts *RestoresStartOpts) newContinuousJobRequest() *atlas.ContinuousJobRequest {

internal/cli/opsmanager/backup/snapshots_list.go

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,19 @@ import (
2222
"github.com/mongodb/mongocli/internal/output"
2323
"github.com/mongodb/mongocli/internal/store"
2424
"github.com/mongodb/mongocli/internal/usage"
25+
"github.com/mongodb/mongocli/internal/validate"
2526
"github.com/spf13/cobra"
2627
)
2728

29+
const snapshotsTemplate = `ID CREATED COMPLETE{{range .Results}}
30+
{{.ID}} {{.Created.Date}} {{.Complete}}{{end}}
31+
`
32+
2833
type SnapshotsListOpts struct {
2934
cli.GlobalOpts
3035
cli.ListOpts
31-
clusterName string
32-
store store.ContinuousSnapshotsLister
36+
clusterID string
37+
store store.ContinuousSnapshotsLister
3338
}
3439

3540
func (opts *SnapshotsListOpts) initStore() error {
@@ -40,27 +45,30 @@ func (opts *SnapshotsListOpts) initStore() error {
4045

4146
func (opts *SnapshotsListOpts) Run() error {
4247
listOpts := opts.NewListOptions()
43-
r, err := opts.store.ContinuousSnapshots(opts.ConfigProjectID(), opts.clusterName, listOpts)
48+
r, err := opts.store.ContinuousSnapshots(opts.ConfigProjectID(), opts.clusterID, listOpts)
4449
if err != nil {
4550
return err
4651
}
4752

48-
return output.Print(config.Default(), "", r)
53+
return output.Print(config.Default(), snapshotsTemplate, r)
4954
}
5055

51-
// mongocli atlas backups snapshots list <clusterId|clusterName> [--projectId projectId] [--page N] [--limit N]
56+
// mongocli atlas backups snapshots list <clusterId> [--projectId projectId] [--page N] [--limit N]
5257
func SnapshotsListBuilder() *cobra.Command {
5358
opts := new(SnapshotsListOpts)
5459
cmd := &cobra.Command{
55-
Use: "list <clusterId|clusterName>",
60+
Use: "list <clusterId>",
5661
Short: description.ListSnapshots,
5762
Aliases: []string{"ls"},
5863
Args: cobra.ExactArgs(1),
5964
PreRunE: func(cmd *cobra.Command, args []string) error {
6065
return opts.PreRunE(opts.initStore)
6166
},
6267
RunE: func(cmd *cobra.Command, args []string) error {
63-
opts.clusterName = args[0]
68+
if err := validate.ObjectID(args[0]); err != nil {
69+
return err
70+
}
71+
opts.clusterID = args[0]
6472

6573
return opts.Run()
6674
},

internal/cli/opsmanager/backup/snapshots_list_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,16 @@ func TestAtlasBackupsSnapshotsList_Run(t *testing.T) {
3030
defer ctrl.Finish()
3131

3232
expected := &mongodbatlas.ContinuousSnapshots{}
33+
clusterID := "5ec2ac941271767f21cbaefe"
3334

3435
listOpts := &SnapshotsListOpts{
35-
store: mockStore,
36-
clusterName: "Cluster0",
36+
store: mockStore,
37+
clusterID: clusterID,
3738
}
3839

3940
mockStore.
4041
EXPECT().
41-
ContinuousSnapshots(listOpts.ProjectID, "Cluster0", listOpts.NewListOptions()).
42+
ContinuousSnapshots(listOpts.ProjectID, clusterID, listOpts.NewListOptions()).
4243
Return(expected, nil).
4344
Times(1)
4445

0 commit comments

Comments
 (0)