summaryrefslogtreecommitdiffstats
path: root/cmd/admin.go
diff options
context:
space:
mode:
Diffstat (limited to 'cmd/admin.go')
-rw-r--r--cmd/admin.go58
1 files changed, 36 insertions, 22 deletions
diff --git a/cmd/admin.go b/cmd/admin.go
index 82e2c29..3c20068 100644
--- a/cmd/admin.go
+++ b/cmd/admin.go
@@ -4,8 +4,8 @@ import (
"fmt"
"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"
- "git.db.org.ai/dborg/internal/utils"
"strconv"
"github.com/spf13/cobra"
@@ -93,7 +93,13 @@ func runAdminList(cmd *cobra.Command, args []string) error {
return fmt.Errorf("API error: %s", response.Error)
}
- return utils.PrintJSON(response.Accounts)
+ output, err := formatter.FormatAccountList(response.Accounts, IsJSONOutput())
+ if err != nil {
+ return err
+ }
+
+ fmt.Print(output)
+ return nil
}
func runAdminCreate(cmd *cobra.Command, args []string) error {
@@ -122,17 +128,12 @@ func runAdminCreate(cmd *cobra.Command, args []string) error {
return fmt.Errorf("API error: %s", response.Error)
}
- if response.Account != nil {
- fmt.Printf("Account created successfully!\n")
- fmt.Printf("Name: %s\n", response.Account.Name)
- fmt.Printf("API Key: %s\n", response.Account.APIKey)
- fmt.Printf("Credits: %d\n", response.Account.Credits)
- fmt.Printf("Unlimited: %v\n", response.Account.Unlimited)
- fmt.Printf("Premium: %v\n", response.Account.IsPremium)
- fmt.Printf("Disabled: %v\n", response.Account.Disabled)
- } else {
- fmt.Println(response.Message)
+ output, err := formatter.FormatAccountCreated(response.Account, response.Message, IsJSONOutput())
+ if err != nil {
+ return err
}
+
+ fmt.Print(output)
return nil
}
@@ -151,7 +152,12 @@ func runAdminDelete(cmd *cobra.Command, args []string) error {
return fmt.Errorf("API error: %s", response.Error)
}
- fmt.Println(response.Message)
+ output, err := formatter.FormatAccountDeleted(response.Message, IsJSONOutput())
+ if err != nil {
+ return err
+ }
+
+ fmt.Print(output)
return nil
}
@@ -175,7 +181,12 @@ func runAdminCredits(cmd *cobra.Command, args []string) error {
return fmt.Errorf("API error: %s", response.Error)
}
- fmt.Println(response.Message)
+ output, err := formatter.FormatCreditsUpdated(response.Message, nil, IsJSONOutput())
+ if err != nil {
+ return err
+ }
+
+ fmt.Print(output)
return nil
}
@@ -199,14 +210,12 @@ func runAdminSetCredits(cmd *cobra.Command, args []string) error {
return fmt.Errorf("API error: %s", response.Error)
}
- if response.Account != nil {
- fmt.Printf("Credits set successfully!\n")
- fmt.Printf("Account: %s\n", response.Account.Name)
- fmt.Printf("API Key: %s\n", response.Account.APIKey)
- fmt.Printf("Credits: %d\n", response.Account.Credits)
- } else if response.Message != "" {
- fmt.Println(response.Message)
+ output, err := formatter.FormatCreditsUpdated(response.Message, response.Account, IsJSONOutput())
+ if err != nil {
+ return err
}
+
+ fmt.Print(output)
return nil
}
@@ -226,6 +235,11 @@ func runAdminDisable(cmd *cobra.Command, args []string) error {
return fmt.Errorf("API error: %s", response.Error)
}
- fmt.Println(response.Message)
+ output, err := formatter.FormatAccountToggled(response.Message, IsJSONOutput())
+ if err != nil {
+ return err
+ }
+
+ fmt.Print(output)
return nil
}