Skip to content

Commit f123277

Browse files
authored
feat(apple-silicon): add autocomplete server type (#3778)
1 parent 141fdb1 commit f123277

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

internal/namespaces/applesilicon/v1alpha1/custom_server.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import (
88
"reflect"
99
"time"
1010

11+
"strings"
12+
1113
"github.com/fatih/color"
1214
"github.com/scaleway/scaleway-cli/v2/internal/core"
1315
"github.com/scaleway/scaleway-cli/v2/internal/human"
@@ -36,6 +38,7 @@ var (
3638
)
3739

3840
func serverCreateBuilder(c *core.Command) *core.Command {
41+
c.ArgSpecs.GetByName("type").AutoCompleteFunc = autocompleteServerType
3942
c.WaitFunc = waitForServerFunc(serverActionCreate)
4043
return c
4144
}
@@ -125,3 +128,27 @@ func serverWaitCommand() *core.Command {
125128
},
126129
}
127130
}
131+
132+
var completeListTypeServerCache *applesilicon.ListServerTypesResponse
133+
134+
func autocompleteServerType(ctx context.Context, prefix string, _ any) core.AutocompleteSuggestions {
135+
suggestions := core.AutocompleteSuggestions(nil)
136+
137+
client := core.ExtractClient(ctx)
138+
api := applesilicon.NewAPI(client)
139+
140+
if completeListTypeServerCache == nil {
141+
res, err := api.ListServerTypes(&applesilicon.ListServerTypesRequest{})
142+
if err != nil {
143+
return nil
144+
}
145+
completeListTypeServerCache = res
146+
}
147+
148+
for _, serverType := range completeListTypeServerCache.ServerTypes {
149+
if strings.HasPrefix(serverType.Name, prefix) {
150+
suggestions = append(suggestions, serverType.Name)
151+
}
152+
}
153+
return suggestions
154+
}

0 commit comments

Comments
 (0)