diff --git a/cli/completer.go b/cli/completer.go index 755cc7f..5984d32 100644 --- a/cli/completer.go +++ b/cli/completer.go @@ -413,6 +413,18 @@ func (t *autoCompleter) Do(line []rune, pos int) (options [][]rune, offset int) return } + if len(arg.AllowedValues) > 0 { + offset = 0 + for _, value := range arg.AllowedValues { + option := value + " " + if strings.HasPrefix(value, argInput) { + options = append(options, []rune(option[len(argInput):])) + offset = len(argInput) + } + } + return + } + autocompleteAPI := findAutocompleteAPI(arg, apiFound, apiMap) if autocompleteAPI == nil { return nil, 0 diff --git a/config/cache.go b/config/cache.go index 510075a..fc083eb 100644 --- a/config/cache.go +++ b/config/cache.go @@ -39,12 +39,13 @@ var bundledAPICache []byte // APIArg are the args passable to an API type APIArg struct { - Name string - Type string - Related []string - Description string - Required bool - Length int + Name string + Type string + Related []string + AllowedValues []string + Description string + Required bool + Length int } // API describes a CloudStack API @@ -143,12 +144,23 @@ func (c *Config) UpdateCache(response map[string]interface{}) interface{} { related = strings.Split(apiArg["related"].(string), ",") sort.Strings(related) } + allowedValues := []string{} + if apiArg["allowedvalues"] != nil { + if rawValues, ok := apiArg["allowedvalues"].([]interface{}); ok { + for _, value := range rawValues { + if str, ok := value.(string); ok { + allowedValues = append(allowedValues, str) + } + } + } + } apiArgs = append(apiArgs, &APIArg{ - Name: apiArg["name"].(string) + "=", - Type: apiArg["type"].(string), - Required: apiArg["required"].(bool), - Related: related, - Description: apiArg["description"].(string), + Name: apiArg["name"].(string) + "=", + Type: apiArg["type"].(string), + Required: apiArg["required"].(bool), + Related: related, + Description: apiArg["description"].(string), + AllowedValues: allowedValues, }) }