-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(completion): use cobras default completion command #204
Conversation
I know this is quite hacky, but so is our current bash completion override which prevents us from supporting zsh (#134) and other shell completions. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. Left non-blocking comment about RE.
internal/completion/helpers.go
Outdated
func RemoveWordBreaks(input string) string { | ||
re := regexp.MustCompile(`\s+`) | ||
return re.ReplaceAllString(input, "\u00A0") | ||
} | ||
|
||
// MatchStringPrefix returns a list of string in vals which have a prefix as specified in key. Quotes are removed from key and output strings are escaped according to completion rules | ||
func MatchStringPrefix(vals []string, key string, caseSensitive bool) []string { | ||
var r []string | ||
key = strings.Trim(key, "'\"") | ||
|
||
for _, v := range vals { | ||
if (caseSensitive && strings.HasPrefix(v, key)) || | ||
(!caseSensitive && strings.HasPrefix(strings.ToLower(v), strings.ToLower(key))) || | ||
key == "" { | ||
r = append(r, Escape(v)) | ||
r = append(r, RemoveWordBreaks(v)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe compile that regular expression before loop and just do re.ReplaceAllString
in loop.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea! Moved the re definition to package-level var.
The linting error seems to come from generics usage in node group parameters parsing, I'll try to see if there a route around that |
…cobra This removes custom bash completion logic and custom completion escape logic as that is not supported by completion scripts cobra generates.
41a51e6
to
7da143e
Compare
This requires removing whitespace from completions as cobras bash completions do not support values with whitespace (See spf13/cobra#1740). This is done by replacing whitespace with non-breaking spaces during completion generation. The argument resolvers with values that can include whitespace are also updated to handle both modified and original arguments, i.e. user can still input whitespaces normally when argument is quoted or escaped.