Skip to content

Commit d22b2a5

Browse files
feat(product_catalog): add product list product-types autocomplete (#5425)
1 parent 0b8c1aa commit d22b2a5

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

internal/namespaces/product_catalog/v2alpha1/custom.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,13 @@ import "github.com/scaleway/scaleway-cli/v2/core"
55
func GetCommands() *core.Commands {
66
cmds := GetGeneratedCommands()
77

8+
cmds.MustFind("product-catalog", "product", "list").Override(productListBuilder)
9+
810
return cmds
911
}
12+
13+
func productListBuilder(c *core.Command) *core.Command {
14+
c.ArgSpecs.GetByName("product-types.{index}").AutoCompleteFunc = autocompleteProductType
15+
16+
return c
17+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package product_catalog
2+
3+
import (
4+
"context"
5+
6+
"github.com/scaleway/scaleway-cli/v2/core"
7+
product_catalog "github.com/scaleway/scaleway-sdk-go/api/product_catalog/v2alpha1"
8+
)
9+
10+
// Caching ListPublicCatalogProductsRequestProductType values for shell completion
11+
var completeProductTypeCache []product_catalog.ListPublicCatalogProductsRequestProductType
12+
13+
func autocompleteProductType(ctx context.Context, _ string, _ any) core.AutocompleteSuggestions {
14+
suggestions := core.AutocompleteSuggestions(nil)
15+
16+
if len(completeProductTypeCache) == 0 {
17+
var productTypes product_catalog.ListPublicCatalogProductsRequestProductType
18+
completeProductTypeCache = productTypes.Values()
19+
}
20+
21+
for _, productType := range completeProductTypeCache {
22+
suggestions = append(suggestions, string(productType))
23+
}
24+
25+
return suggestions
26+
}

0 commit comments

Comments
 (0)