-
Notifications
You must be signed in to change notification settings - Fork 8
/
list.go
84 lines (78 loc) · 2.04 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package ipaddress
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"
)
// ListCommand creates the "ip-address list" command
func ListCommand() commands.Command {
return &listCommand{
BaseCommand: commands.New("list", "List IP addresses", "upctl ip-address list"),
}
}
type listCommand struct {
*commands.BaseCommand
}
// InitCommand implements Command.MakeExecuteCommand
func (s *listCommand) InitCommand() {
// TODO: reimplement
// flags := &pflag.FlagSet{}
// s.AddVisibleColumnsFlag(flags, &s.visibleColumns, s.columnKeys, s.visibleColumns)
// s.AddFlags(flags)
}
// ExecuteWithoutArguments implements commands.NoArgumentCommand
func (s *listCommand) ExecuteWithoutArguments(exec commands.Executor) (output.Output, error) {
ips, err := exec.IPAddress().GetIPAddresses(exec.Context())
if err != nil {
return nil, err
}
rows := make([]output.TableRow, len(ips.IPAddresses))
for i, ipAddress := range ips.IPAddresses {
rows[i] = output.TableRow{ipAddress.Address, ipAddress.Access, ipAddress.Family, ipAddress.PartOfPlan, ipAddress.PTRRecord, ipAddress.ServerUUID, ipAddress.Floating, ipAddress.Zone}
}
return output.MarshaledWithHumanOutput{
Value: ips,
Output: output.Table{
Columns: []output.TableColumn{
{
Header: "Address",
Key: "address",
Colour: ui.DefaultAddressColours,
},
{
Header: "Access",
Key: "access",
},
{
Header: "Family",
Key: "family",
},
{
Header: "Part of Plan",
Key: "part_of_plan",
Format: format.Boolean,
},
{
Header: "PTR Record",
Key: "ptr_record",
},
{
Header: "Server",
Key: "server",
Colour: ui.DefaultUUUIDColours,
},
{
Header: "Floating",
Key: "floating",
Format: format.Boolean,
},
{
Header: "Zone",
Key: "zone",
},
},
Rows: rows,
},
}, nil
}