From d1142f57e8145e1166205c085f2ed90ed5f5195f Mon Sep 17 00:00:00 2001 From: jo Date: Tue, 24 Feb 2026 15:19:39 +0100 Subject: [PATCH 1/2] feat: add location column to server type table --- internal/cmd/servertype/list.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/internal/cmd/servertype/list.go b/internal/cmd/servertype/list.go index 3f3d794ec..c50fe1945 100644 --- a/internal/cmd/servertype/list.go +++ b/internal/cmd/servertype/list.go @@ -12,13 +12,14 @@ import ( "github.com/hetznercloud/cli/internal/hcapi2" "github.com/hetznercloud/cli/internal/state" "github.com/hetznercloud/hcloud-go/v2/hcloud" + "github.com/hetznercloud/hcloud-go/v2/hcloud/exp/kit/sliceutil" "github.com/hetznercloud/hcloud-go/v2/hcloud/schema" ) var ListCmd = &base.ListCmd[*hcloud.ServerType, schema.ServerType]{ ResourceNamePlural: "Server Types", JSONKeyGetByName: "server_types", - DefaultColumns: []string{"id", "name", "cores", "cpu_type", "architecture", "memory", "disk", "storage_type"}, + DefaultColumns: []string{"id", "name", "cores", "cpu_type", "architecture", "memory", "disk", "storage_type", "location"}, SortOption: nil, // Server Types do not support sorting Fetch: func(s state.State, _ *pflag.FlagSet, listOpts hcloud.ListOpts, sorts []string) ([]*hcloud.ServerType, error) { @@ -32,6 +33,13 @@ var ListCmd = &base.ListCmd[*hcloud.ServerType, schema.ServerType]{ OutputTable: func(t *output.Table[*hcloud.ServerType], _ hcapi2.Client) { t. AddAllowedFields(&hcloud.ServerType{}). + AddFieldFn("location", func(serverType *hcloud.ServerType) string { + locationNames := sliceutil.Transform( + serverType.Locations, + func(l hcloud.ServerTypeLocation) string { return l.Location.Name }, + ) + return strings.Join(locationNames, ",") + }). AddFieldAlias("storagetype", "storage type"). AddFieldFn("memory", func(serverType *hcloud.ServerType) string { return fmt.Sprintf("%.1f GB", serverType.Memory) From 578190aa3dba52a3ad5fb4a800a6433a1377ce96 Mon Sep 17 00:00:00 2001 From: jo Date: Tue, 24 Feb 2026 16:26:54 +0100 Subject: [PATCH 2/2] feat: remove `storage_type` from default server types table columns --- docs/reference/manual/hcloud_server-type_list.md | 1 + internal/cmd/servertype/list.go | 2 +- internal/cmd/servertype/list_test.go | 9 +++++++-- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/docs/reference/manual/hcloud_server-type_list.md b/docs/reference/manual/hcloud_server-type_list.md index 5f7d7722e..5e705a3b0 100644 --- a/docs/reference/manual/hcloud_server-type_list.md +++ b/docs/reference/manual/hcloud_server-type_list.md @@ -20,6 +20,7 @@ Columns: - disk - id - included_traffic + - location - memory - name - storage_type diff --git a/internal/cmd/servertype/list.go b/internal/cmd/servertype/list.go index c50fe1945..f162e8014 100644 --- a/internal/cmd/servertype/list.go +++ b/internal/cmd/servertype/list.go @@ -19,7 +19,7 @@ import ( var ListCmd = &base.ListCmd[*hcloud.ServerType, schema.ServerType]{ ResourceNamePlural: "Server Types", JSONKeyGetByName: "server_types", - DefaultColumns: []string{"id", "name", "cores", "cpu_type", "architecture", "memory", "disk", "storage_type", "location"}, + DefaultColumns: []string{"id", "name", "cores", "cpu_type", "architecture", "memory", "disk", "location"}, SortOption: nil, // Server Types do not support sorting Fetch: func(s state.State, _ *pflag.FlagSet, listOpts hcloud.ListOpts, sorts []string) ([]*hcloud.ServerType, error) { diff --git a/internal/cmd/servertype/list_test.go b/internal/cmd/servertype/list_test.go index d598980df..1c363291e 100644 --- a/internal/cmd/servertype/list_test.go +++ b/internal/cmd/servertype/list_test.go @@ -40,13 +40,18 @@ func TestList(t *testing.T) { Memory: 8.0, Disk: 80, StorageType: hcloud.StorageTypeLocal, + Locations: []hcloud.ServerTypeLocation{ + {Location: &hcloud.Location{ID: 1, Name: "fsn1"}}, + {Location: &hcloud.Location{ID: 2, Name: "nbg1"}}, + {Location: &hcloud.Location{ID: 3, Name: "hel1"}}, + }, }, }, nil) out, errOut, err := fx.Run(cmd, []string{}) - expOut := `ID NAME CORES CPU TYPE ARCHITECTURE MEMORY DISK STORAGE TYPE -123 test 2 shared arm 8.0 GB 80 GB local + expOut := `ID NAME CORES CPU TYPE ARCHITECTURE MEMORY DISK LOCATION +123 test 2 shared arm 8.0 GB 80 GB fsn1,nbg1,hel1 ` require.NoError(t, err)