-
Notifications
You must be signed in to change notification settings - Fork 19
/
db_type_list.go
68 lines (51 loc) · 1.71 KB
/
db_type_list.go
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package cmd
import (
"fmt"
"strings"
exoapi "github.com/exoscale/egoscale/v2/api"
"github.com/spf13/cobra"
)
type dbTypeListItemOutput struct {
Name string `json:"name"`
LatestVersion string `json:"latest_version"`
DefaultVersion string `json:"default_version"`
}
type dbTypeListOutput []dbTypeListItemOutput
func (o *dbTypeListOutput) toJSON() { outputJSON(o) }
func (o *dbTypeListOutput) toText() { outputText(o) }
func (o *dbTypeListOutput) toTable() { outputTable(o) }
type dbTypeListCmd struct {
_ bool `cli-cmd:"list"`
}
func (c *dbTypeListCmd) cmdAliases() []string { return nil }
func (c *dbTypeListCmd) cmdShort() string { return "List Database Service types" }
func (c *dbTypeListCmd) cmdLong() string {
return fmt.Sprintf(`This command lists available Database Service types.
Supported output template annotations: %s`,
strings.Join(outputterTemplateAnnotations(&dbTypeListItemOutput{}), ", "))
}
func (c *dbTypeListCmd) cmdPreRun(cmd *cobra.Command, args []string) error {
return cliCommandDefaultPreRun(c, cmd, args)
}
func (c *dbTypeListCmd) cmdRun(_ *cobra.Command, _ []string) error {
ctx := exoapi.WithEndpoint(
gContext,
exoapi.NewReqEndpoint(gCurrentAccount.Environment, gCurrentAccount.DefaultZone),
)
dbTypes, err := cs.ListDatabaseServiceTypes(ctx, gCurrentAccount.DefaultZone)
if err != nil {
return err
}
out := make(dbTypeListOutput, 0)
for _, t := range dbTypes {
out = append(out, dbTypeListItemOutput{
Name: *t.Name,
DefaultVersion: defaultString(t.DefaultVersion, "-"),
LatestVersion: defaultString(t.LatestVersion, "-"),
})
}
return output(&out, nil)
}
func init() {
cobra.CheckErr(registerCLICommand(dbTypeCmd, &dbTypeListCmd{}))
}