github.com/DaAlbrecht/cf-cli@v0.0.0-20231128151943-1fe19bb400b9/command/flag/completions.go (about)

     1  package flag
     2  
     3  import (
     4  	"strings"
     5  
     6  	flags "github.com/jessevdk/go-flags"
     7  )
     8  
     9  func completions(options []string, prefix string, caseSensitive bool) []flags.Completion {
    10  	if !caseSensitive {
    11  		prefix = strings.ToLower(prefix)
    12  	}
    13  
    14  	matches := make([]flags.Completion, 0, len(options))
    15  	for _, option := range options {
    16  		casedOption := option
    17  		if !caseSensitive {
    18  			casedOption = strings.ToLower(option)
    19  		}
    20  		if strings.HasPrefix(casedOption, prefix) {
    21  			matches = append(matches, flags.Completion{Item: option})
    22  		}
    23  	}
    24  
    25  	return matches
    26  }