-
Notifications
You must be signed in to change notification settings - Fork 6
/
show.go
69 lines (62 loc) · 2.1 KB
/
show.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 ipaddress
import (
"github.com/UpCloudLtd/upcloud-cli/v3/internal/commands"
"github.com/UpCloudLtd/upcloud-cli/v3/internal/completion"
"github.com/UpCloudLtd/upcloud-cli/v3/internal/format"
"github.com/UpCloudLtd/upcloud-cli/v3/internal/output"
"github.com/UpCloudLtd/upcloud-cli/v3/internal/resolver"
"github.com/UpCloudLtd/upcloud-cli/v3/internal/ui"
"github.com/UpCloudLtd/upcloud-go-api/v8/upcloud/request"
)
// ShowCommand creates the 'ip-address show' command
func ShowCommand() commands.Command {
return &showCommand{
BaseCommand: commands.New(
"show",
"Show current IP address",
"upctl ip-address show 185.70.196.47",
"upctl ip-address show 2a04:3544:8000:1000:d40e:4aff:fe6f:5d34",
),
}
}
type showCommand struct {
*commands.BaseCommand
completion.IPAddress
resolver.CachingIPAddress
}
// InitCommand implements Command.InitCommand
func (s *showCommand) InitCommand() {
}
func (s *showCommand) Execute(exec commands.Executor, arg string) (output.Output, error) {
ipAddress, err := exec.IPAddress().GetIPAddressDetails(exec.Context(), &request.GetIPAddressDetailsRequest{
Address: arg,
})
if err != nil {
return nil, err
}
details := output.Details{
Sections: []output.DetailSection{
{
Rows: []output.DetailRow{
{Title: "Address:", Key: "address", Value: ipAddress.Address, Colour: ui.DefaultAddressColours},
{Title: "Access:", Key: "access", Value: ipAddress.Access},
{Title: "Family:", Key: "family", Value: ipAddress.Family},
{Title: "Part of Plan:", Key: "part_of_plan", Value: ipAddress.PartOfPlan, Format: format.Boolean},
{Title: "PTR Record:", Key: "ptr_record", Value: ipAddress.PTRRecord},
{
Title: "Server UUID:",
Key: "server", Value: ipAddress.ServerUUID,
Colour: ui.DefaultUUUIDColours,
},
{Title: "MAC:", Key: "mac", Value: ipAddress.MAC},
{Title: "Floating:", Key: "floating", Value: ipAddress.Floating, Format: format.Boolean},
{Title: "Zone:", Key: "zone", Value: ipAddress.Zone},
},
},
},
}
return output.MarshaledWithHumanOutput{
Value: ipAddress,
Output: details,
}, nil
}