File tree 5 files changed +20
-19
lines changed 5 files changed +20
-19
lines changed Original file line number Diff line number Diff line change @@ -43,19 +43,19 @@ func (b *bash) ProgramName() string {
43
43
44
44
const bashCompletionTemplate = `
45
45
_generate_{{.Name}}_completions() {
46
- # Capture the line excluding the command, and everything after the current word
47
46
local args=("${COMP_WORDS[@]:1:COMP_CWORD}")
48
47
49
- # Set COMPLETION_MODE and call the command with the arguments, capturing the output
50
- local completions=$ (COMPLETION_MODE=1 "{{.Name}}" "${args[@]}")
48
+ declare -a output
49
+ mapfile -t output < < (COMPLETION_MODE=1 "{{.Name}}" "${args[@]}")
51
50
52
- # Use the command's output to generate completions for the current word
53
- COMPREPLY=($( compgen -W "$completions" -- "${COMP_WORDS[COMP_CWORD ]}"))
51
+ declare -a completions
52
+ mapfile -t completions < <( compgen -W "$(printf '%q ' "${output[@ ]}")" -- "$2" )
54
53
55
- # Ensure no files are shown, even if there are no matches
56
- if [ ${#COMPREPLY[@]} -eq 0 ]; then
57
- COMPREPLY=()
58
- fi
54
+ local comp
55
+ COMPREPLY=()
56
+ for comp in "${completions[@]}"; do
57
+ COMPREPLY+=("$(printf "%q" "$comp")")
58
+ done
59
59
}
60
60
# Setup Bash to use the function for completions for '{{.Name}}'
61
61
complete -F _generate_{{.Name}}_completions {{.Name}}
Original file line number Diff line number Diff line change @@ -80,7 +80,7 @@ $_{{.Name}}_completions = {
80
80
Invoke-Expression $Command | Where-Object { $_ -like "$wordToComplete*" } | ForEach-Object {
81
81
"$_" | _{{.Name}}_escapeStringWithSpecialChars
82
82
}
83
- rm env:COMPLETION_MODE
83
+ $ env:COMPLETION_MODE = ''
84
84
}
85
85
Register-ArgumentCompleter -CommandName {{.Name}} -ScriptBlock $_{{.Name}}_completions
86
86
`
Original file line number Diff line number Diff line change @@ -42,7 +42,7 @@ const zshCompletionTemplate = `
42
42
_{{.Name}}_completions() {
43
43
local -a args completions
44
44
args=("${words[@]:1:$#words}")
45
- completions=($( COMPLETION_MODE=1 "{{.Name}}" "${args[@]}"))
45
+ completions=(${(f)"$( COMPLETION_MODE=1 "{{.Name}}" "${args[@]}")"} )
46
46
compadd -a completions
47
47
}
48
48
compdef _{{.Name}}_completions {{.Name}}
Original file line number Diff line number Diff line change @@ -352,7 +352,7 @@ func (optSet OptionSet) ByFlag(flag string) *Option {
352
352
}
353
353
for i := range optSet {
354
354
opt := & optSet [i ]
355
- if opt .Flag == flag || opt . FlagShorthand == flag {
355
+ if opt .Flag == flag {
356
356
return opt
357
357
}
358
358
}
Original file line number Diff line number Diff line change @@ -530,7 +530,7 @@ func EnumOf(v *string, choices ...string) *Enum {
530
530
531
531
func (e * Enum ) Set (v string ) error {
532
532
for _ , c := range e .Choices {
533
- if v == c {
533
+ if strings . EqualFold ( v , c ) {
534
534
* e .Value = v
535
535
return nil
536
536
}
@@ -642,7 +642,7 @@ type EnumArray struct {
642
642
643
643
func (e * EnumArray ) Append (s string ) error {
644
644
for _ , c := range e .Choices {
645
- if s == c {
645
+ if strings . EqualFold ( s , c ) {
646
646
* e .Value = append (* e .Value , s )
647
647
return nil
648
648
}
@@ -658,7 +658,7 @@ func (e *EnumArray) Replace(ss []string) error {
658
658
for _ , s := range ss {
659
659
found := false
660
660
for _ , c := range e .Choices {
661
- if s == c {
661
+ if strings . EqualFold ( s , c ) {
662
662
found = true
663
663
break
664
664
}
@@ -680,11 +680,12 @@ func (e *EnumArray) Set(v string) error {
680
680
if err != nil {
681
681
return err
682
682
}
683
- err = e .Replace (ss )
684
- if err != nil {
685
- return err
683
+ for _ , s := range ss {
684
+ err := e .Append (s )
685
+ if err != nil {
686
+ return err
687
+ }
686
688
}
687
- * e .Value = append (* e .Value , ss ... )
688
689
return nil
689
690
}
690
691
You can’t perform that action at this time.
0 commit comments