@@ -20,6 +20,7 @@ package cli
20
20
import (
21
21
"fmt"
22
22
"sort"
23
+ "strconv"
23
24
"strings"
24
25
"unicode"
25
26
@@ -123,7 +124,14 @@ func buildArgOptions(response map[string]interface{}, hasID bool) []argOption {
123
124
}
124
125
var id , name , detail string
125
126
if resource ["id" ] != nil {
126
- id = resource ["id" ].(string )
127
+ switch rawID := resource ["id" ].(type ) {
128
+ case string :
129
+ id = rawID
130
+ case float64 :
131
+ id = strconv .FormatFloat (rawID , 'f' , - 1 , 64 )
132
+ default :
133
+ 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 ))
134
+ }
127
135
}
128
136
if resource ["name" ] != nil {
129
137
name = resource ["name" ].(string )
@@ -417,15 +425,23 @@ func (t *autoCompleter) Do(line []rune, pos int) (options [][]rune, offset int)
417
425
response , _ := cmd .NewAPIRequest (request , autocompleteAPI .Name , autocompleteAPIArgs , false )
418
426
t .Config .StopSpinner (spinner )
419
427
420
- hasID := strings .HasSuffix (arg .Name , "id=" ) || strings .HasSuffix (arg .Name , "ids=" )
428
+ hasID := strings .HasSuffix (arg .Name , "id=" ) || strings .HasSuffix (arg .Name , "ids=" ) || autocompleteAPI . Name == "listUsageTypes"
421
429
argOptions = buildArgOptions (response , hasID )
422
430
}
423
431
424
432
filteredOptions := []argOption {}
425
433
if len (argOptions ) > 0 {
426
- sort .Slice (argOptions , func (i , j int ) bool {
427
- return argOptions [i ].Value < argOptions [j ].Value
428
- })
434
+ if autocompleteAPI .Name == "listUsageTypes" {
435
+ sort .Slice (argOptions , func (i , j int ) bool {
436
+ i , _ = strconv .Atoi (argOptions [i ].Value )
437
+ j , _ = strconv .Atoi (argOptions [j ].Value )
438
+ return i < j
439
+ })
440
+ } else {
441
+ sort .Slice (argOptions , func (i , j int ) bool {
442
+ return argOptions [i ].Value < argOptions [j ].Value
443
+ })
444
+ }
429
445
for _ , item := range argOptions {
430
446
if strings .HasPrefix (item .Value , argInput ) {
431
447
filteredOptions = append (filteredOptions , item )
0 commit comments