Skip to content
Myr

make filename extension handling a bash function

Before adoption: this commit came in with the history the project adopted, so no landing records it.

We were trying to call a bash function with bash stuff like @ () from a variable. Stop that. Just call a function with an arg from a variable instead of trying to pass around the bash. Should fix https://github.com/spf13/cobra/pull/103

authored by Eric Paris · committed by Eric Paris · parent 787b737 · Browse files · 2 files+9 added−2 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+9 added−2 removed

  • other:+9 added−2 removed

2 files+9 added−2 removed

modified:bash_completions_test.go+1 added-1 removed
74 unmodified lines
75 check(t, str, `COMPREPLY=( "hello" )`)76 // check for required nouns77 check(t, str, `must_have_one_noun+=("pods")`)78 // check for filename extention flags79 check(t, str, `flags_completion+=("_filedir '@(json|yaml|yml)'")`)79 check(t, str, `flags_completion+=("__handle_filename_extension_flag json|yaml|yml")`)8081 checkOmit(t, str, cmdDeprecated.Name())82}
modified:bash_completions.go+8 added-1 removed
91 unmodified lines
92 declare -F __custom_func >/dev/null && __custom_func93 fi94}9596# The arguments should be in the form "ext1|ext2|extn"97__handle_filename_extension_flag()98{99 local ext="$1"100 _filedir "@(${ext})"101}102103__handle_flag()104{105 __debug "${FUNCNAME}: c is $c words[c] is ${words[c]}"106
112 unmodified lines
219 case BashCompFilenameExt:220 fmt.Fprintf(out, " flags_with_completion+=(%q)\n", name)221222 ext := strings.Join(value, "|")216 ext = "_filedir '@(" + ext + ")'"223 ext = "__handle_filename_extension_flag " + ext224 fmt.Fprintf(out, " flags_completion+=(%q)\n", ext)225 }226 }227}
130 unmodified lines