Skip to content

Commit

Permalink
feat(apple-silicon): add autocomplete server type (#3778)
Browse files Browse the repository at this point in the history
  • Loading branch information
Laure-di authored Apr 18, 2024
1 parent 141fdb1 commit f123277
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions internal/namespaces/applesilicon/v1alpha1/custom_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"reflect"
"time"

"strings"

"github.com/fatih/color"
"github.com/scaleway/scaleway-cli/v2/internal/core"
"github.com/scaleway/scaleway-cli/v2/internal/human"
Expand Down Expand Up @@ -36,6 +38,7 @@ var (
)

func serverCreateBuilder(c *core.Command) *core.Command {
c.ArgSpecs.GetByName("type").AutoCompleteFunc = autocompleteServerType
c.WaitFunc = waitForServerFunc(serverActionCreate)
return c
}
Expand Down Expand Up @@ -125,3 +128,27 @@ func serverWaitCommand() *core.Command {
},
}
}

var completeListTypeServerCache *applesilicon.ListServerTypesResponse

func autocompleteServerType(ctx context.Context, prefix string, _ any) core.AutocompleteSuggestions {
suggestions := core.AutocompleteSuggestions(nil)

client := core.ExtractClient(ctx)
api := applesilicon.NewAPI(client)

if completeListTypeServerCache == nil {
res, err := api.ListServerTypes(&applesilicon.ListServerTypesRequest{})
if err != nil {
return nil
}
completeListTypeServerCache = res
}

for _, serverType := range completeListTypeServerCache.ServerTypes {
if strings.HasPrefix(serverType.Name, prefix) {
suggestions = append(suggestions, serverType.Name)
}
}
return suggestions
}

0 comments on commit f123277

Please sign in to comment.