Skip to content
Open
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
12 changes: 12 additions & 0 deletions cli/completer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
34 changes: 23 additions & 11 deletions config/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any rationale to add it in the middle?

Description string
Required bool
Length int
}

// API describes a CloudStack API
Expand Down Expand Up @@ -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,
})
}

Expand Down