Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions internal/cmd/servertype/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package servertype

import (
"fmt"
"slices"
"strings"
"time"

Expand Down Expand Up @@ -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 {
Expand Down
9 changes: 7 additions & 2 deletions internal/cmd/servertype/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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"}},
},
Expand All @@ -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)
Expand Down
Loading