diff options
Diffstat (limited to 'cmd/services.go')
| -rw-r--r-- | cmd/services.go | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/cmd/services.go b/cmd/services.go new file mode 100644 index 0000000..56c2149 --- /dev/null +++ b/cmd/services.go @@ -0,0 +1,49 @@ +package cmd + +import ( + "encoding/json" + "fmt" + + "github.com/spf13/cobra" +) + +var servicesCmd = &cobra.Command{ + Use: "services", + Short: "List all available services and pricing", + Long: `Get a list of all available services and their credit costs`, + RunE: runServices, +} + +func init() { + rootCmd.AddCommand(servicesCmd) +} + +func runServices(cmd *cobra.Command, args []string) error { + c, err := newUnauthenticatedClient() + if err != nil { + return err + } + + data, err := c.ListServices() + if err != nil { + return err + } + + if IsJSONOutput() { + fmt.Println(string(data)) + return nil + } + + var services map[string]interface{} + if err := json.Unmarshal(data, &services); err != nil { + return fmt.Errorf("failed to parse services: %w", err) + } + + fmt.Println("\nAvailable Services:") + fmt.Println("===================\n") + + servicesData, _ := json.MarshalIndent(services, "", " ") + fmt.Println(string(servicesData)) + + return nil +} |
