@@ -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 restoreListTemplate = `ID SNAPSHOT CLUSTER TYPE EXPIRES AT{{range valueOrEmptySlice .Results}}
4647{{.Id}} {{.SnapshotId}} {{.TargetClusterName}} {{.DeliveryType}} {{.ExpiresAt}}{{end}}
4748`
49+ var restoreListFlexClusterTemplate = `ID SNAPSHOT CLUSTER TYPE EXPIRES AT{{range valueOrEmptySlice .Results}}
50+ {{.Id}} {{.SnapshotId}} {{.TargetDeploymentItemName}} {{.DeliveryType}} {{.ExpirationDate}}{{end}}
51+ `
4852
4953func (opts * ListOpts ) Run () error {
54+ r , err := opts .store .RestoreFlexClusterJobs (opts .newListFlexBackupRestoreJobsAPIParams ())
55+ if err == nil {
56+ opts .Template = restoreListFlexClusterTemplate
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 .RestoreJobs (opts .ConfigProjectID (), opts .clusterName , listOpts )
70+ restoreJobs , err := opts .store .RestoreJobs (opts .ConfigProjectID (), opts .clusterName , listOpts )
5271 if err != nil {
5372 return err
5473 }
5574
56- return opts .Print (r )
75+ return opts .Print (restoreJobs )
76+ }
77+
78+ func (opts * ListOpts ) newListFlexBackupRestoreJobsAPIParams () * atlasv2.ListFlexBackupRestoreJobsApiParams {
79+ includeCount := ! opts .OmitCount
80+ return & atlasv2.ListFlexBackupRestoreJobsApiParams {
81+ GroupId : opts .ConfigProjectID (),
82+ Name : opts .clusterName ,
83+ IncludeCount : & includeCount ,
84+ ItemsPerPage : & opts .ItemsPerPage ,
85+ PageNum : & opts .PageNum ,
86+ }
5787}
5888
89+ // ListBuilder builds a cobra.Command that can run as:
5990// atlas backup(s) restore(s) job(s) list <clusterName> [--page N] [--limit N].
6091func ListBuilder () * cobra.Command {
6192 opts := new (ListOpts )
0 commit comments