Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make command Run error return consistent #419

Merged
merged 5 commits into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions cmd/account/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package account
import (
"context"
"errors"
"fmt"

"github.com/spf13/cobra"
"github.com/vultr/govultr/v3"
Expand Down Expand Up @@ -34,10 +35,15 @@ func NewCmdAccount(base *cli.Base) *cobra.Command {
}
return nil
},
Run: func(cmd *cobra.Command, args []string) {
RunE: func(cmd *cobra.Command, args []string) error {
account, err := o.get()
if err != nil {
return fmt.Errorf("error retrieving account information : %v", err)
}

o.Base.Printer.Display(&AccountPrinter{Account: account}, nil)

o.Base.Printer.Display(&AccountPrinter{Account: account}, err)
return nil
},
}

Expand Down
15 changes: 8 additions & 7 deletions cmd/backups/backups.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@ package backups
import (
"errors"
"fmt"
"os"

"github.com/spf13/cobra"
"github.com/vultr/govultr/v3"
"github.com/vultr/vultr-cli/v3/cmd/printer"
"github.com/vultr/vultr-cli/v3/cmd/utils"
"github.com/vultr/vultr-cli/v3/pkg/cli"
)
Expand Down Expand Up @@ -48,15 +46,16 @@ func NewCmdBackups(base *cli.Base) *cobra.Command {
Aliases: []string{"l"},
Long: listLong,
Example: listExample,
Run: func(cmd *cobra.Command, args []string) {
RunE: func(cmd *cobra.Command, args []string) error {
o.Base.Options = utils.GetPaging(cmd)
backups, meta, err := o.list()
if err != nil {
printer.Error(fmt.Errorf("error retrieving backups list : %v", err))
os.Exit(1)
return fmt.Errorf("error retrieving backups list : %v", err)
}
data := &BackupsPrinter{Backups: backups, Meta: meta}
o.Base.Printer.Display(data, err)

return nil
},
}

Expand All @@ -80,14 +79,16 @@ func NewCmdBackups(base *cli.Base) *cobra.Command {
}
return nil
},
Run: func(cmd *cobra.Command, args []string) {
RunE: func(cmd *cobra.Command, args []string) error {
backup, err := o.get()
if err != nil {
panic(fmt.Errorf("error retrieving backup : %v", err))
return fmt.Errorf("error retrieving backup : %v", err)
}

data := &BackupPrinter{Backup: backup}
o.Base.Printer.Display(data, err)

return nil
},
}

Expand Down
Loading
Loading