-
Notifications
You must be signed in to change notification settings - Fork 6
/
list.go
69 lines (61 loc) · 2.11 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
62
63
64
65
66
67
68
69
package databaseindex
import (
"fmt"
"github.com/UpCloudLtd/upcloud-cli/v2/internal/commands"
"github.com/UpCloudLtd/upcloud-cli/v2/internal/completion"
"github.com/UpCloudLtd/upcloud-cli/v2/internal/format"
"github.com/UpCloudLtd/upcloud-cli/v2/internal/output"
"github.com/UpCloudLtd/upcloud-cli/v2/internal/resolver"
"github.com/UpCloudLtd/upcloud-cli/v2/internal/ui"
"github.com/UpCloudLtd/upcloud-go-api/v6/upcloud/request"
)
// ListCommand creates the "database index list" command
func ListCommand() commands.Command {
return &listCommand{
BaseCommand: commands.New("list", "List current indices of the specified databases", "upctl database index list 55199a44-4751-4e27-9394-7c7661910be3"),
}
}
type listCommand struct {
*commands.BaseCommand
resolver.CachingDatabase
completion.Database
}
// Execute implements commands.MultipleArgumentCommand
func (s *listCommand) Execute(exec commands.Executor, uuid string) (output.Output, error) {
svc := exec.All()
indices, err := svc.GetManagedDatabaseIndices(exec.Context(), &request.GetManagedDatabaseIndicesRequest{ServiceUUID: uuid})
if err != nil {
return nil, err
}
rows := []output.TableRow{}
for _, index := range indices {
rows = append(rows, output.TableRow{
index.IndexName,
index.CreateTime,
index.Health,
index.Status,
index.Docs,
index.NumberOfReplicas,
index.NumberOfShards,
index.ReadOnlyAllowDelete,
fmt.Sprintf("%d bytes", index.Size),
})
}
return output.MarshaledWithHumanOutput{
Value: indices,
Output: output.Table{
Columns: []output.TableColumn{
{Key: "index_name", Header: "Name", Colour: ui.DefaultUUUIDColours},
{Key: "create_time", Header: "Created"},
{Key: "health", Header: "Health", Format: format.DatabaseIndexHealth},
{Key: "status", Header: "Status", Format: format.DatabaseIndexState},
{Key: "docs", Header: "Documents"},
{Key: "number_of_replicas", Header: "Replicas"},
{Key: "number_of_shards", Header: "Shards"},
{Key: "read_only_allow_delete", Header: "Read-only & allow delete", Format: format.Boolean},
{Key: "size", Header: "Size"},
},
Rows: rows,
},
}, nil
}