Skip to content

Commit e6b6abe

Browse files
committed
add available column to server type list
1 parent 8c64fa1 commit e6b6abe

2 files changed

Lines changed: 21 additions & 8 deletions

File tree

docs/reference/manual/hcloud_server-type_list.md

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/cmd/servertype/list.go

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,18 @@ var ListCmd = &base.ListCmd[*hcloud.ServerType, schema.ServerType]{
3737
AddFieldFn("location", func(serverType *hcloud.ServerType) string {
3838
now := time.Now()
3939
return strings.Join(
40-
sliceutil.Transform(
41-
slices.DeleteFunc(
42-
slices.Clone(serverType.Locations),
43-
func(l hcloud.ServerTypeLocation) bool { return l.IsDeprecated() && l.UnavailableAfter().Before(now) },
44-
),
45-
func(l hcloud.ServerTypeLocation) string { return l.Location.Name },
46-
),
40+
listLocationNames(serverType, func(l hcloud.ServerTypeLocation) bool {
41+
return l.IsDeprecated() && l.UnavailableAfter().Before(now)
42+
}),
43+
",",
44+
)
45+
}).
46+
AddFieldFn("available", func(serverType *hcloud.ServerType) string {
47+
now := time.Now()
48+
return strings.Join(
49+
listLocationNames(serverType, func(l hcloud.ServerTypeLocation) bool {
50+
return (l.IsDeprecated() && l.UnavailableAfter().Before(now)) || !l.Available
51+
}),
4752
",",
4853
)
4954
}).
@@ -79,3 +84,10 @@ var ListCmd = &base.ListCmd[*hcloud.ServerType, schema.ServerType]{
7984

8085
Schema: hcloud.SchemaFromServerType,
8186
}
87+
88+
func listLocationNames(serverType *hcloud.ServerType, del func(hcloud.ServerTypeLocation) bool) []string {
89+
return sliceutil.Transform(
90+
slices.DeleteFunc(slices.Clone(serverType.Locations), del),
91+
func(l hcloud.ServerTypeLocation) string { return l.Location.Name },
92+
)
93+
}

0 commit comments

Comments
 (0)