diff --git a/internal/namespaces/product_catalog/v2alpha1/custom.go b/internal/namespaces/product_catalog/v2alpha1/custom.go index 97d03a9eef..5568e856cd 100644 --- a/internal/namespaces/product_catalog/v2alpha1/custom.go +++ b/internal/namespaces/product_catalog/v2alpha1/custom.go @@ -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 +} diff --git a/internal/namespaces/product_catalog/v2alpha1/custom_product.go b/internal/namespaces/product_catalog/v2alpha1/custom_product.go new file mode 100644 index 0000000000..2c7f509987 --- /dev/null +++ b/internal/namespaces/product_catalog/v2alpha1/custom_product.go @@ -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 +}