From f438705217952ce59f5d846132ff2a2878ec99c3 Mon Sep 17 00:00:00 2001 From: pauhull Date: Tue, 31 Oct 2023 11:32:27 +0100 Subject: [PATCH] fix(primary-ip): list does now allow to output IP column 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 --- internal/cmd/floatingip/list.go | 1 + internal/cmd/primaryip/list.go | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/internal/cmd/floatingip/list.go b/internal/cmd/floatingip/list.go index 553499ef..5d379cee 100644 --- a/internal/cmd/floatingip/list.go +++ b/internal/cmd/floatingip/list.go @@ -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() } diff --git a/internal/cmd/primaryip/list.go b/internal/cmd/primaryip/list.go index f366de1a..89cfe443 100644 --- a/internal/cmd/primaryip/list.go +++ b/internal/cmd/primaryip/list.go @@ -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