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
8 changes: 8 additions & 0 deletions internal/namespaces/product_catalog/v2alpha1/custom.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,13 @@ import "github.com/scaleway/scaleway-cli/v2/core"
func GetCommands() *core.Commands {
cmds := GetGeneratedCommands()

cmds.MustFind("product-catalog", "product", "list").Override(productListBuilder)

return cmds
}

func productListBuilder(c *core.Command) *core.Command {
c.ArgSpecs.GetByName("product-types.{index}").AutoCompleteFunc = autocompleteProductType

return c
}
26 changes: 26 additions & 0 deletions internal/namespaces/product_catalog/v2alpha1/custom_product.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package product_catalog

import (
"context"

"github.com/scaleway/scaleway-cli/v2/core"
product_catalog "github.com/scaleway/scaleway-sdk-go/api/product_catalog/v2alpha1"
)

// Caching ListPublicCatalogProductsRequestProductType values for shell completion
var completeProductTypeCache []product_catalog.ListPublicCatalogProductsRequestProductType

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

if len(completeProductTypeCache) == 0 {
var productTypes product_catalog.ListPublicCatalogProductsRequestProductType
completeProductTypeCache = productTypes.Values()
}

for _, productType := range completeProductTypeCache {
suggestions = append(suggestions, string(productType))
}

return suggestions
}
Loading