diff options
Diffstat (limited to 'cmd/admin.go')
| -rw-r--r-- | cmd/admin.go | 44 |
1 files changed, 21 insertions, 23 deletions
diff --git a/cmd/admin.go b/cmd/admin.go index 3c20068..b0c3e13 100644 --- a/cmd/admin.go +++ b/cmd/admin.go @@ -2,12 +2,11 @@ package cmd import ( "fmt" + "strconv" + "git.db.org.ai/dborg/internal/client" - "git.db.org.ai/dborg/internal/config" "git.db.org.ai/dborg/internal/formatter" "git.db.org.ai/dborg/internal/models" - "strconv" - "github.com/spf13/cobra" ) @@ -74,8 +73,7 @@ func init() { } func getAdminClient(cmd *cobra.Command) (*client.Client, error) { - cfg := config.New() - return client.New(cfg) + return newClient() } func runAdminList(cmd *cobra.Command, args []string) error { @@ -89,8 +87,8 @@ func runAdminList(cmd *cobra.Command, args []string) error { return err } - if response.Error != "" { - return fmt.Errorf("API error: %s", response.Error) + if err := checkError(response.Error); err != nil { + return err } output, err := formatter.FormatAccountList(response.Accounts, IsJSONOutput()) @@ -98,7 +96,7 @@ func runAdminList(cmd *cobra.Command, args []string) error { return err } - fmt.Print(output) + printOutput(output) return nil } @@ -124,8 +122,8 @@ func runAdminCreate(cmd *cobra.Command, args []string) error { return err } - if response.Error != "" { - return fmt.Errorf("API error: %s", response.Error) + if err := checkError(response.Error); err != nil { + return err } output, err := formatter.FormatAccountCreated(response.Account, response.Message, IsJSONOutput()) @@ -133,7 +131,7 @@ func runAdminCreate(cmd *cobra.Command, args []string) error { return err } - fmt.Print(output) + printOutput(output) return nil } @@ -148,8 +146,8 @@ func runAdminDelete(cmd *cobra.Command, args []string) error { return err } - if response.Error != "" { - return fmt.Errorf("API error: %s", response.Error) + if err := checkError(response.Error); err != nil { + return err } output, err := formatter.FormatAccountDeleted(response.Message, IsJSONOutput()) @@ -157,7 +155,7 @@ func runAdminDelete(cmd *cobra.Command, args []string) error { return err } - fmt.Print(output) + printOutput(output) return nil } @@ -177,8 +175,8 @@ func runAdminCredits(cmd *cobra.Command, args []string) error { return err } - if response.Error != "" { - return fmt.Errorf("API error: %s", response.Error) + if err := checkError(response.Error); err != nil { + return err } output, err := formatter.FormatCreditsUpdated(response.Message, nil, IsJSONOutput()) @@ -186,7 +184,7 @@ func runAdminCredits(cmd *cobra.Command, args []string) error { return err } - fmt.Print(output) + printOutput(output) return nil } @@ -206,8 +204,8 @@ func runAdminSetCredits(cmd *cobra.Command, args []string) error { return err } - if response.Error != "" { - return fmt.Errorf("API error: %s", response.Error) + if err := checkError(response.Error); err != nil { + return err } output, err := formatter.FormatCreditsUpdated(response.Message, response.Account, IsJSONOutput()) @@ -215,7 +213,7 @@ func runAdminSetCredits(cmd *cobra.Command, args []string) error { return err } - fmt.Print(output) + printOutput(output) return nil } @@ -231,8 +229,8 @@ func runAdminDisable(cmd *cobra.Command, args []string) error { return err } - if response.Error != "" { - return fmt.Errorf("API error: %s", response.Error) + if err := checkError(response.Error); err != nil { + return err } output, err := formatter.FormatAccountToggled(response.Message, IsJSONOutput()) @@ -240,6 +238,6 @@ func runAdminDisable(cmd *cobra.Command, args []string) error { return err } - fmt.Print(output) + printOutput(output) return nil } |
