@@ -24,6 +24,7 @@ import (
2424 "github.com/mongodb/mongodb-atlas-cli/atlascli/internal/store"
2525 "github.com/mongodb/mongodb-atlas-cli/atlascli/internal/usage"
2626 "github.com/spf13/cobra"
27+ atlasv2 "go.mongodb.org/atlas-sdk/v20241113002/admin"
2728)
2829
2930type ListOpts struct {
@@ -45,17 +46,47 @@ func (opts *ListOpts) initStore(ctx context.Context) func() error {
4546var listTemplate = `ID TYPE STATUS CREATED AT EXPIRES AT{{range valueOrEmptySlice .Results}}
4647{{.Id}} {{.SnapshotType}} {{.Status}} {{.CreatedAt}} {{.ExpiresAt}}{{end}}
4748`
49+ var listTemplateFlex = `ID STATUS MONGODB VERSION START TIME FINISH TIME EXPIRATION{{range valueOrEmptySlice .Results}}
50+ {{.Id}} {{.Status}} {{.MongoDBVersion}} {{.StartTime}} {{.FinishTime}} {{.Expiration}}{{end}}
51+ `
4852
4953func (opts * ListOpts ) Run () error {
54+ r , err := opts .store .FlexClusterSnapshots (opts .newListFlexBackupsAPIParams ())
55+ if err == nil {
56+ opts .Template = listTemplateFlex
57+ return opts .Print (r )
58+ }
59+
60+ apiError , ok := atlasv2 .AsError (err )
61+ if ! ok {
62+ return err
63+ }
64+
65+ if apiError .ErrorCode != cannotUseNotFlexWithFlexApisErrorCode {
66+ return err
67+ }
68+
5069 listOpts := opts .NewListOptions ()
51- r , err := opts .store .Snapshots (opts .ConfigProjectID (), opts .clusterName , listOpts )
70+ snapshotsList , err := opts .store .Snapshots (opts .ConfigProjectID (), opts .clusterName , listOpts )
5271 if err != nil {
5372 return err
5473 }
5574
56- return opts .Print (r )
75+ return opts .Print (snapshotsList )
76+ }
77+
78+ func (opts * ListOpts ) newListFlexBackupsAPIParams () * atlasv2.ListFlexBackupsApiParams {
79+ includeCount := ! opts .ListOpts .OmitCount
80+ return & atlasv2.ListFlexBackupsApiParams {
81+ GroupId : opts .ConfigProjectID (),
82+ Name : opts .clusterName ,
83+ IncludeCount : & includeCount ,
84+ ItemsPerPage : & opts .ListOpts .ItemsPerPage ,
85+ PageNum : & opts .ListOpts .PageNum ,
86+ }
5787}
5888
89+ // ListBuilder builds a cobra.Command that can run as:
5990// atlas backups snapshots list <clusterName> [--projectId projectId] [--page N] [--limit N].
6091func ListBuilder () * cobra.Command {
6192 opts := new (ListOpts )
0 commit comments