@@ -291,7 +291,7 @@ func AutoComplete(ctx context.Context, leftWords []string, wordToComplete string
291291 }
292292
293293 // keep track of the completed args
294- completedArgs := make (map [string ]struct {} )
294+ completedArgs := make (map [string ]string )
295295
296296 // keep track of the completed flags
297297 completedFlags := make (map [string ]struct {})
@@ -307,12 +307,12 @@ func AutoComplete(ctx context.Context, leftWords []string, wordToComplete string
307307
308308 // handle arg=value
309309 case isArg (word ):
310- completedArgs [wordKey (word )+ "=" ] = struct {}{}
310+ completedArgs [wordKey (word )+ "=" ] = wordValue ( word )
311311
312312 // handle boolean arg
313313 default :
314314 if _ , exist := node .Children [positionalValueNodeID ]; exist && i > nodeIndexInWords {
315- completedArgs [word ] = struct {}{}
315+ completedArgs [word ] = ""
316316 }
317317 }
318318 }
@@ -324,7 +324,7 @@ func AutoComplete(ctx context.Context, leftWords []string, wordToComplete string
324324 // We try to complete the value of an unknown arg
325325 return & AutocompleteResponse {}
326326 }
327- suggestions := AutoCompleteArgValue (ctx , argNode .Command , argNode .ArgSpec , argValuePrefix )
327+ suggestions := AutoCompleteArgValue (ctx , argNode .Command , argNode .ArgSpec , argValuePrefix , completedArgs )
328328
329329 // We need to prefix suggestions with the argName to enable the arg value auto-completion.
330330 for k , s := range suggestions {
@@ -338,7 +338,7 @@ func AutoComplete(ctx context.Context, leftWords []string, wordToComplete string
338338 suggestions := []string (nil )
339339 for key , child := range node .Children {
340340 if key == positionalValueNodeID {
341- for _ , positionalSuggestion := range AutoCompleteArgValue (ctx , child .Command , child .ArgSpec , wordToComplete ) {
341+ for _ , positionalSuggestion := range AutoCompleteArgValue (ctx , child .Command , child .ArgSpec , wordToComplete , completedArgs ) {
342342 if _ , exists := completedArgs [positionalSuggestion ]; ! exists {
343343 suggestions = append (suggestions , positionalSuggestion )
344344 }
@@ -380,7 +380,7 @@ func AutoComplete(ctx context.Context, leftWords []string, wordToComplete string
380380// AutoCompleteArgValue returns suggestions for a (argument name, argument value prefix) pair.
381381// Priority is given to the AutoCompleteFunc from the ArgSpec, if it is set.
382382// Otherwise, we use EnumValues from the ArgSpec.
383- func AutoCompleteArgValue (ctx context.Context , cmd * Command , argSpec * ArgSpec , argValuePrefix string ) []string {
383+ func AutoCompleteArgValue (ctx context.Context , cmd * Command , argSpec * ArgSpec , argValuePrefix string , completedArgs map [ string ] string ) []string {
384384 if argSpec == nil {
385385 return nil
386386 }
@@ -401,6 +401,12 @@ func AutoCompleteArgValue(ctx context.Context, cmd *Command, argSpec *ArgSpec, a
401401 possibleValues = argSpec .EnumValues
402402 }
403403
404+ // Complete arg value using list verb if possible
405+ // "instance server get <tab>" completes "server-id" arg with "id" in instance server list
406+ if len (possibleValues ) == 0 && ExtractBetaMode (ctx ) {
407+ possibleValues = AutocompleteGetArg (ctx , cmd , argSpec , completedArgs )
408+ }
409+
404410 suggestions := []string (nil )
405411 for _ , value := range possibleValues {
406412 if strings .HasPrefix (value , argValuePrefix ) {
@@ -424,6 +430,14 @@ func wordKey(word string) string {
424430 return strings .SplitN (word , "=" , 2 )[0 ]
425431}
426432
433+ func wordValue (word string ) string {
434+ words := strings .SplitN (word , "=" , 2 )
435+ if len (words ) >= 2 {
436+ return words [1 ]
437+ }
438+ return ""
439+ }
440+
427441func isArg (wordToComplete string ) bool {
428442 return strings .Contains (wordToComplete , "=" )
429443}
@@ -460,7 +474,7 @@ func hasPrefix(key, wordToComplete string) bool {
460474
461475// keySuggestion will suggest the next key available for the map (or array) argument.
462476// Keys are suggested in ascending order arg.0, arg.1, arg.2...
463- func keySuggestion (key string , completedArg map [string ]struct {} , wordToComplete string ) []string {
477+ func keySuggestion (key string , completedArg map [string ]string , wordToComplete string ) []string {
464478 splitKey := strings .Split (key , "." )
465479 splitWordToComplete := strings .Split (wordToComplete , "." )
466480
0 commit comments