Skip to content

Commit

Permalink
Add support for json response in restore watch commands (#2097)
Browse files Browse the repository at this point in the history
  • Loading branch information
blva authored Jul 19, 2023
1 parent 23128eb commit a4aeb2a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
7 changes: 5 additions & 2 deletions internal/cli/atlas/backup/restores/watch.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"github.com/mongodb/mongodb-atlas-cli/internal/store"
"github.com/mongodb/mongodb-atlas-cli/internal/usage"
"github.com/spf13/cobra"
atlasv2 "go.mongodb.org/atlas-sdk/v20230201002/admin"
)

type WatchOpts struct {
Expand All @@ -36,6 +37,7 @@ type WatchOpts struct {
}

var watchTemplate = "\nRestore completed.\n"
var result *atlasv2.DiskBackupSnapshotRestoreJob

func (opts *WatchOpts) initStore(ctx context.Context) func() error {
return func() error {
Expand All @@ -46,7 +48,8 @@ func (opts *WatchOpts) initStore(ctx context.Context) func() error {
}

func (opts *WatchOpts) watcher() (bool, error) {
result, err := opts.store.RestoreJob(opts.ConfigProjectID(), opts.clusterName, opts.id)
var err error
result, err = opts.store.RestoreJob(opts.ConfigProjectID(), opts.clusterName, opts.id)
if err != nil {
return false, err
}
Expand All @@ -59,7 +62,7 @@ func (opts *WatchOpts) Run() error {
return err
}

return opts.Print(nil)
return opts.Print(result)
}

// WatchBuilder atlas backup(s) restore(s) job(s) watch <restoreJobId>.
Expand Down
7 changes: 5 additions & 2 deletions internal/cli/atlas/serverless/backup/restores/watch.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"github.com/mongodb/mongodb-atlas-cli/internal/store"
"github.com/mongodb/mongodb-atlas-cli/internal/usage"
"github.com/spf13/cobra"
atlasv2 "go.mongodb.org/atlas-sdk/v20230201002/admin"
)

type WatchOpts struct {
Expand All @@ -36,6 +37,7 @@ type WatchOpts struct {
}

var watchTemplate = "\nRestore completed.\n"
var result *atlasv2.ServerlessBackupRestoreJob

func (opts *WatchOpts) initStore(ctx context.Context) func() error {
return func() error {
Expand All @@ -46,7 +48,8 @@ func (opts *WatchOpts) initStore(ctx context.Context) func() error {
}

func (opts *WatchOpts) watcher() (bool, error) {
result, err := opts.store.ServerlessRestoreJob(opts.ConfigProjectID(), opts.clusterName, opts.id)
var err error
result, err = opts.store.ServerlessRestoreJob(opts.ConfigProjectID(), opts.clusterName, opts.id)
if err != nil {
return false, err
}
Expand All @@ -58,7 +61,7 @@ func (opts *WatchOpts) Run() error {
return err
}

return opts.Print(nil)
return opts.Print(result)
}

// WatchBuilder atlas serverless backup(s) restore(s) watch.
Expand Down
8 changes: 6 additions & 2 deletions internal/cli/mongocli/serverless/backup/restores/watch.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"github.com/mongodb/mongodb-atlas-cli/internal/store"
"github.com/mongodb/mongodb-atlas-cli/internal/usage"
"github.com/spf13/cobra"
atlasv2 "go.mongodb.org/atlas-sdk/v20230201002/admin"
)

type WatchOpts struct {
Expand All @@ -35,6 +36,8 @@ type WatchOpts struct {
store store.ServerlessRestoreJobsDescriber
}

var result *atlasv2.ServerlessBackupRestoreJob

func (opts *WatchOpts) initStore(ctx context.Context) func() error {
return func() error {
var err error
Expand All @@ -44,7 +47,8 @@ func (opts *WatchOpts) initStore(ctx context.Context) func() error {
}

func (opts *WatchOpts) watcher() (bool, error) {
result, err := opts.store.ServerlessRestoreJob(opts.ConfigProjectID(), opts.clusterName, opts.id)
var err error
result, err = opts.store.ServerlessRestoreJob(opts.ConfigProjectID(), opts.clusterName, opts.id)
if err != nil {
return false, err
}
Expand All @@ -56,7 +60,7 @@ func (opts *WatchOpts) Run() error {
return err
}

return opts.Print(nil)
return opts.Print(result)
}

// WatchBuilder atlas serverless backup(s) restore(s) watch.
Expand Down

0 comments on commit a4aeb2a

Please sign in to comment.