Skip to content
Myr

Merge pull request #210 from boz/colon-completion

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

Bash completion for names with ':' character.

authored by Eric Paris · committed by Eric Paris · parents ea3bf16, fe79245 · Browse files · 3 files+14 added−3 removed
This commit

State

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

Diff stats

3 files+14 added−3 removed

  • other:+14 added−3 removed

3 files+14 added−3 removed

modified:bash_completions_test.go+2 added-1 removed
32 unmodified lines
3334func TestBashCompletions(t *testing.T) {35 c := initializeWithRootCmd()36 cmdEcho.AddCommand(cmdTimes)37 c.AddCommand(cmdEcho, cmdPrint, cmdDeprecated)37 c.AddCommand(cmdEcho, cmdPrint, cmdDeprecated, cmdColon)3839 // custom completion function40 c.BashCompletionFunction = bash_completion_func41
32 unmodified lines
74 check(t, str, "_cobra-test")75 check(t, str, "_cobra-test_echo")76 check(t, str, "_cobra-test_echo_times")77 check(t, str, "_cobra-test_print")78 check(t, str, "_cobra-test_cmd__colon")7980 // check for required flags81 check(t, str, `must_have_one_flag+=("--introot=")`)82 check(t, str, `must_have_one_flag+=("--persistent-filename=")`)
13 unmodified lines
modified:bash_completions.go+6 added-2 removed
101 unmodified lines
102103 if [[ ${#COMPREPLY[@]} -eq 0 ]]; then104 declare -F __custom_func >/dev/null && __custom_func105 fi106107 __ltrim_colon_completions "$cur"108}109110# The arguments should be in the form "ext1|ext2|extn"111__handle_filename_extension_flag()
55 unmodified lines
167 __debug "${FUNCNAME}: c is $c words[c] is ${words[c]}"168169 local next_command170 if [[ -n ${last_command} ]]; then169 next_command="_${last_command}_${words[c]}"171 next_command="_${last_command}_${words[c]//:/__}"172 else171 next_command="_${words[c]}"173 next_command="_${words[c]//:/__}"174 fi175 c=$((c+1))176 __debug "${FUNCNAME}: looking for ${next_command}"177 declare -F $next_command >/dev/null && $next_command
19 unmodified lines
197`)198}199200func postscript(out *bytes.Buffer, name string) {201 name = strings.Replace(name, ":", "__", -1)202 fmt.Fprintf(out, "__start_%s()\n", name)203 fmt.Fprintf(out, `{204 local cur prev words cword205 if declare -F _init_completion >/dev/null 2>&1; then
151 unmodified lines
357 gen(c, out)358 }359 commandName := cmd.CommandPath()360 commandName = strings.Replace(commandName, " ", "_", -1)361 commandName = strings.Replace(commandName, ":", "__", -1)362 fmt.Fprintf(out, "_%s()\n{\n", commandName)363 fmt.Fprintf(out, " last_command=%q\n", commandName)364 writeCommands(cmd, out)365 writeFlags(cmd, out)
64 unmodified lines
modified:cobra_test.go+6 added
141 unmodified lines
142 versionUsed = 2143 },144}145146var cmdColon = &Command{147 Use: "cmd:colon",148 Run: func(cmd *Command, args []string) {149 },150}151152func flagInit() {153 cmdEcho.ResetFlags()154 cmdPrint.ResetFlags()155 cmdTimes.ResetFlags()
1014 unmodified lines