This is an automated email from the ASF dual-hosted git repository. shwstppr pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/cloudstack-cloudmonkey.git
The following commit(s) were added to refs/heads/main by this push: new 902d732 Fix usagetype parameter autocomplete (#156) 902d732 is described below commit 902d7325e3bd2c54074978bc530c8f04424fff9f Author: Henrique Sato <henriquesato2...@gmail.com> AuthorDate: Wed Aug 13 04:08:18 2025 -0300 Fix usagetype parameter autocomplete (#156) * Fix usage type autocomplete --------- Co-authored-by: Henrique Sato <henrique.s...@scclouds.com.br> --- cli/completer.go | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/cli/completer.go b/cli/completer.go index 53de5fb..bd1f1df 100644 --- a/cli/completer.go +++ b/cli/completer.go @@ -20,6 +20,7 @@ package cli import ( "fmt" "sort" + "strconv" "strings" "unicode" @@ -123,7 +124,14 @@ func buildArgOptions(response map[string]interface{}, hasID bool) []argOption { } var id, name, detail string if resource["id"] != nil { - id = resource["id"].(string) + switch rawID := resource["id"].(type) { + case string: + id = rawID + case float64: + id = strconv.FormatFloat(rawID, 'f', -1, 64) + default: + panic(fmt.Errorf("detected an invalid type at path (%v:%T). This should have been caught during validation, indicating a bug in CloudMonkey. Please report this issue", rawID, rawID)) + } } if resource["name"] != nil { name = resource["name"].(string) @@ -417,15 +425,23 @@ func (t *autoCompleter) Do(line []rune, pos int) (options [][]rune, offset int) response, _ := cmd.NewAPIRequest(request, autocompleteAPI.Name, autocompleteAPIArgs, false) t.Config.StopSpinner(spinner) - hasID := strings.HasSuffix(arg.Name, "id=") || strings.HasSuffix(arg.Name, "ids=") + hasID := strings.HasSuffix(arg.Name, "id=") || strings.HasSuffix(arg.Name, "ids=") || autocompleteAPI.Name == "listUsageTypes" argOptions = buildArgOptions(response, hasID) } filteredOptions := []argOption{} if len(argOptions) > 0 { - sort.Slice(argOptions, func(i, j int) bool { - return argOptions[i].Value < argOptions[j].Value - }) + if autocompleteAPI.Name == "listUsageTypes" { + sort.Slice(argOptions, func(i, j int) bool { + i, _ = strconv.Atoi(argOptions[i].Value) + j, _ = strconv.Atoi(argOptions[j].Value) + return i < j + }) + } else { + sort.Slice(argOptions, func(i, j int) bool { + return argOptions[i].Value < argOptions[j].Value + }) + } for _, item := range argOptions { if strings.HasPrefix(item.Value, argInput) { filteredOptions = append(filteredOptions, item)