diff --git a/internal/cmd/servertype/list.go b/internal/cmd/servertype/list.go index f162e8014..5c987ca95 100644 --- a/internal/cmd/servertype/list.go +++ b/internal/cmd/servertype/list.go @@ -2,6 +2,7 @@ package servertype import ( "fmt" + "slices" "strings" "time" @@ -34,11 +35,17 @@ var ListCmd = &base.ListCmd[*hcloud.ServerType, schema.ServerType]{ 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 }, + now := time.Now() + return strings.Join( + sliceutil.Transform( + slices.DeleteFunc( + slices.Clone(serverType.Locations), + func(l hcloud.ServerTypeLocation) bool { return l.IsDeprecated() && l.UnavailableAfter().Before(now) }, + ), + func(l hcloud.ServerTypeLocation) string { return l.Location.Name }, + ), + ",", ) - return strings.Join(locationNames, ",") }). AddFieldAlias("storagetype", "storage type"). AddFieldFn("memory", func(serverType *hcloud.ServerType) string { diff --git a/internal/cmd/servertype/list_test.go b/internal/cmd/servertype/list_test.go index 702a162fa..148f211d5 100644 --- a/internal/cmd/servertype/list_test.go +++ b/internal/cmd/servertype/list_test.go @@ -21,6 +21,11 @@ func TestList(t *testing.T) { cmd := servertype.ListCmd.CobraCommand(fx.State()) + serverTypeDeprecation := hcloud.DeprecatableResource{Deprecation: &hcloud.DeprecationInfo{ + Announced: time.Date(2025, 1, 1, 0, 0, 0, 0, time.UTC), + UnavailableAfter: time.Date(2025, 4, 1, 0, 0, 0, 0, time.UTC), + }} + fx.ExpectEnsureToken() fx.Client.ServerTypeClient.EXPECT(). AllWithOpts( @@ -41,7 +46,7 @@ func TestList(t *testing.T) { Disk: 80, StorageType: hcloud.StorageTypeLocal, Locations: []hcloud.ServerTypeLocation{ - {Location: &hcloud.Location{ID: 1, Name: "fsn1"}}, + {Location: &hcloud.Location{ID: 1, Name: "fsn1"}, DeprecatableResource: serverTypeDeprecation}, {Location: &hcloud.Location{ID: 2, Name: "nbg1"}}, {Location: &hcloud.Location{ID: 3, Name: "hel1"}}, }, @@ -51,7 +56,7 @@ func TestList(t *testing.T) { out, errOut, err := fx.Run(cmd, []string{}) expOut := `ID NAME CORES CPU TYPE ARCHITECTURE MEMORY DISK LOCATION -123 test 2 shared arm 8.0 GB 80 GB fsn1,nbg1,hel1 +123 test 2 shared arm 8.0 GB 80 GB nbg1,hel1 ` require.NoError(t, err)