mirror of
https://github.com/spf13/cobra
synced 2025-05-07 13:57:21 +00:00
Make sure we quote brackets when generating zsh completion
Signed-off-by: Chmouel Boudjnah <chmouel@chmouel.com>
This commit is contained in:
parent
89c7ffb512
commit
8d84e2e222
2 changed files with 14 additions and 1 deletions
|
@ -332,5 +332,7 @@ func zshCompFlagCouldBeSpecifiedMoreThenOnce(f *pflag.Flag) bool {
|
|||
}
|
||||
|
||||
func zshCompQuoteFlagDescription(s string) string {
|
||||
return strings.Replace(s, "'", `'\''`, -1)
|
||||
return strings.NewReplacer("'", `'\''`,
|
||||
"[", `\[`,
|
||||
"]", `\]`).Replace(s)
|
||||
}
|
||||
|
|
|
@ -157,6 +157,17 @@ func TestGenZshCompletion(t *testing.T) {
|
|||
`--private\[Don'\\''t show public info]`,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "flag description with brackets ([]) shouldn't break the completion file",
|
||||
root: func() *Command {
|
||||
r := genTestCommand("root", true)
|
||||
r.Flags().Bool("level", false, "[ALERT]")
|
||||
return r
|
||||
}(),
|
||||
expectedExpressions: []string{
|
||||
`--level[\[ALERT\]]`,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "argument completion for file with and without patterns",
|
||||
root: func() *Command {
|
||||
|
|
Loading…
Add table
Reference in a new issue