summaryrefslogtreecommitdiffstats
path: root/cmd/me.go
blob: e5ba7ec825032d631b96b02775cdc9b98452fb7a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package cmd

import (
	"git.db.org.ai/dborg/internal/formatter"
	"github.com/spf13/cobra"
)

var meCmd = &cobra.Command{
	Use:   "me",
	Short: "Get account information and usage statistics",
	Long:  `Get your account information, credits, and usage statistics.`,
	RunE:  runMe,
}

func init() {
	rootCmd.AddCommand(meCmd)
}

func runMe(cmd *cobra.Command, args []string) error {
	c, err := newClient()
	if err != nil {
		return err
	}

	response, err := c.GetAccountStats()
	if err != nil {
		return err
	}

	if err := checkError(response.Error); err != nil {
		return err
	}

	output, err := formatter.FormatAccountStats(response, IsJSONOutput())
	if err != nil {
		return err
	}

	printOutput(output)
	return nil
}