-
Notifications
You must be signed in to change notification settings - Fork 6
/
list.go
66 lines (58 loc) · 1.9 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
package objectstorage
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/paging"
"github.com/UpCloudLtd/upcloud-cli/v3/internal/ui"
"github.com/spf13/pflag"
"github.com/UpCloudLtd/upcloud-go-api/v8/upcloud/request"
)
// ListCommand creates the "objectstorage list" command
func ListCommand() commands.Command {
return &listCommand{
BaseCommand: commands.New("list", "List current Managed object storage services", "upctl objectstorage list"),
}
}
type listCommand struct {
*commands.BaseCommand
paging.PageParameters
}
func (c *listCommand) InitCommand() {
fs := &pflag.FlagSet{}
c.ConfigureFlags(fs)
c.AddFlags(fs)
}
// ExecuteWithoutArguments implements commands.NoArgumentCommand
func (c *listCommand) ExecuteWithoutArguments(exec commands.Executor) (output.Output, error) {
svc := exec.All()
objectstorages, err := svc.GetManagedObjectStorages(exec.Context(), &request.GetManagedObjectStoragesRequest{
Page: c.Page(),
})
if err != nil {
return nil, err
}
rows := []output.TableRow{}
for _, objectstorage := range objectstorages {
rows = append(rows, output.TableRow{
objectstorage.UUID,
objectstorage.Name,
objectstorage.Region,
objectstorage.ConfiguredStatus,
objectstorage.OperationalState,
})
}
return output.MarshaledWithHumanOutput{
Value: objectstorages,
Output: output.Table{
Columns: []output.TableColumn{
{Key: "uuid", Header: "UUID", Colour: ui.DefaultUUUIDColours},
{Key: "name", Header: "Name"},
{Key: "region", Header: "Region"},
{Key: "configured_status", Header: "Configured status", Format: format.ObjectStorageConfiguredStatus},
{Key: "operational_state", Header: "Operational state", Format: format.ObjectStorageOperationalState},
},
Rows: rows,
},
}, nil
}