-
Notifications
You must be signed in to change notification settings - Fork 6
/
types.go
48 lines (42 loc) · 1.27 KB
/
types.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
package database
import (
"github.com/UpCloudLtd/upcloud-cli/v3/internal/commands"
"github.com/UpCloudLtd/upcloud-cli/v3/internal/output"
"github.com/UpCloudLtd/upcloud-go-api/v8/upcloud/request"
)
// TypesCommand creates the "database types" command
func TypesCommand() commands.Command {
return &typesCommand{
BaseCommand: commands.New("types", "List available database types", "upctl database types"),
}
}
type typesCommand struct {
*commands.BaseCommand
}
// ExecuteWithoutArguments implements commands.NoArgumentCommand
func (s *typesCommand) ExecuteWithoutArguments(exec commands.Executor) (output.Output, error) {
svc := exec.All()
dbTypes, err := svc.GetManagedDatabaseServiceTypes(exec.Context(), &request.GetManagedDatabaseServiceTypesRequest{})
if err != nil {
return nil, err
}
rows := []output.TableRow{}
for _, dbType := range dbTypes {
rows = append(rows, output.TableRow{
dbType.Name,
dbType.Description,
dbType.LatestAvailableVersion,
})
}
return output.MarshaledWithHumanOutput{
Value: dbTypes,
Output: output.Table{
Columns: []output.TableColumn{
{Key: "name", Header: "Name"},
{Key: "description", Header: "Description"},
{Key: "latest_available_version", Header: "Latest Available Version"},
},
Rows: rows,
},
}, nil
}