@@ -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+
2833type SnapshotsListOpts struct {
2934 cli.GlobalOpts
3035 cli.ListOpts
31- clusterName string
32- store store.ContinuousSnapshotsLister
36+ clusterID string
37+ store store.ContinuousSnapshotsLister
3338}
3439
3540func (opts * SnapshotsListOpts ) initStore () error {
@@ -40,27 +45,30 @@ func (opts *SnapshotsListOpts) initStore() error {
4045
4146func (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]
5257func 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 },
0 commit comments