Skip to content

Commit

Permalink
fix(primary-ip): list does now allow to output IP column (#594)
Browse files Browse the repository at this point in the history
Since IP is a ``*hcloud.PrimaryIP``, ``AddAllowedFields()`` only adds
columns for primitive types and a field function for IP was missing, you
were not able to output the IP column using output flags.

Closes #591
  • Loading branch information
phm07 committed Oct 31, 2023
1 parent b70dfe3 commit ee8e6ed
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions internal/cmd/floatingip/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ var ListCmd = base.ListCmd{
})).
AddFieldFn("ip", output.FieldFn(func(obj interface{}) string {
floatingIP := obj.(*hcloud.FloatingIP)
// Format IPv6 correctly
if floatingIP.Network != nil {
return floatingIP.Network.String()
}
Expand Down
8 changes: 8 additions & 0 deletions internal/cmd/primaryip/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ var ListCmd = base.ListCmd{
OutputTable: func(client hcapi2.Client) *output.Table {
return output.NewTable().
AddAllowedFields(hcloud.PrimaryIP{}).
AddFieldFn("ip", output.FieldFn(func(obj interface{}) string {
primaryIP := obj.(*hcloud.PrimaryIP)
// Format IPv6 correctly
if primaryIP.Network != nil {
return primaryIP.Network.String()
}
return primaryIP.IP.String()
})).
AddFieldFn("dns", output.FieldFn(func(obj interface{}) string {
primaryIP := obj.(*hcloud.PrimaryIP)
var dns string
Expand Down

0 comments on commit ee8e6ed

Please sign in to comment.