-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(completion): use the default completion command provided by …
…cobra This removes custom bash completion logic and custom completion escape logic as that is not supperted by completion scripts cobra generates.
- Loading branch information
Showing
7 changed files
with
8 additions
and
174 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,19 @@ | ||
package completion | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
) | ||
|
||
// 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, v) | ||
} | ||
} | ||
return r | ||
} | ||
|
||
// Escape escapes a string according to completion rules (?) | ||
// in effect, this means that the string will be quoted with double quotes if it contains a space or parentheses. | ||
func Escape(s string) string { | ||
if strings.ContainsAny(s, ` ()`) { | ||
return fmt.Sprintf(`"%s"`, s) | ||
} | ||
return s | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters