-
Notifications
You must be signed in to change notification settings - Fork 7
/
list.go
61 lines (54 loc) · 1.52 KB
/
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
package database
import (
"github.com/UpCloudLtd/upcloud-cli/v3/internal/commands"
"github.com/UpCloudLtd/upcloud-cli/v3/internal/format"
"github.com/UpCloudLtd/upcloud-cli/v3/internal/output"
"github.com/UpCloudLtd/upcloud-cli/v3/internal/ui"
"github.com/UpCloudLtd/upcloud-go-api/v6/upcloud/request"
)
// ListCommand creates the "database list" command
func ListCommand() commands.Command {
return &listCommand{
BaseCommand: commands.New("list", "List current databases", "upctl database list"),
}
}
type listCommand struct {
*commands.BaseCommand
}
// ExecuteWithoutArguments implements commands.NoArgumentCommand
func (s *listCommand) ExecuteWithoutArguments(exec commands.Executor) (output.Output, error) {
svc := exec.All()
databases, err := svc.GetManagedDatabases(exec.Context(), &request.GetManagedDatabasesRequest{})
if err != nil {
return nil, err
}
rows := []output.TableRow{}
for _, db := range databases {
title := db.Title
if title == "" {
title = db.Name
}
rows = append(rows, output.TableRow{
db.UUID,
title,
db.Type,
db.Plan,
db.Zone,
db.State,
})
}
return output.MarshaledWithHumanOutput{
Value: databases,
Output: output.Table{
Columns: []output.TableColumn{
{Key: "uuid", Header: "UUID", Colour: ui.DefaultUUUIDColours},
{Key: "title", Header: "Title"},
{Key: "type", Header: "Type"},
{Key: "plan", Header: "Plan"},
{Key: "zone", Header: "Zone"},
{Key: "state", Header: "State", Format: format.DatabaseState},
},
Rows: rows,
},
}, nil
}