Skip to content

Commit

Permalink
Merge pull request #105 from rsteube/fix-completion
Browse files Browse the repository at this point in the history
fix completion
  • Loading branch information
rsteube authored Oct 29, 2020
2 parents 73fe8b0 + 04d2a61 commit b1194c1
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 23 deletions.
38 changes: 19 additions & 19 deletions example/cmd/root_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1232,7 +1232,7 @@ func TestZsh(t *testing.T) {
expected := `#compdef example
function _example_callback {
# shellcheck disable=SC2086
eval "$(example _carapace zsh "$5" ${os_args})"
eval "$(example _carapace zsh "$1" ${os_args})"
}
function _example {
local -a commands
Expand Down Expand Up @@ -1292,14 +1292,14 @@ function _example__action {
_arguments -C \
"--directories[files flag]: :_files -/" \
"(-f --files)"{-f,--files}"[files flag]: :_files -g '*.go'" \
"(-g --groups)"{-g,--groups}"[groups flag]: :_example_callback '_example__action##groups'" \
"--hosts[hosts flag]: :_example_callback '_example__action##hosts'" \
"(-g --groups)"{-g,--groups}"[groups flag]: :{_example_callback '_example__action##groups'}" \
"--hosts[hosts flag]: :{_example_callback '_example__action##hosts'}" \
"(-k --kill)"{-k,--kill}"[kill signals]: :{local _comp_desc=('ABRT (Abnormal termination)' 'ALRM (Virtual alarm clock)' 'BUS (BUS error)' 'CHLD (Child status has changed)' 'CONT (Continue stopped process)' 'FPE (Floating-point exception)' 'HUP (Hangup detected on controlling terminal)' 'ILL (Illegal instruction)' 'INT (Interrupt from keyboard)' 'KILL (Kill, unblockable)' 'PIPE (Broken pipe)' 'POLL (Pollable event occurred)' 'PROF (Profiling alarm clock timer expired)' 'PWR (Power failure restart)' 'QUIT (Quit from keyboard)' 'SEGV (Segmentation violation)' 'STKFLT (Stack fault on coprocessor)' 'STOP (Stop process, unblockable)' 'SYS (Bad system call)' 'TERM (Termination request)' 'TRAP (Trace/breakpoint trap)' 'TSTP (Stop typed at keyboard)' 'TTIN (Background read from tty)' 'TTOU (Background write to tty)' 'URG (Urgent condition on socket)' 'USR1 (User-defined signal 1)' 'USR2 (User-defined signal 2)' 'VTALRM (Virtual alarm clock)' 'WINCH (Window size change)' 'XCPU (CPU time limit exceeded)' 'XFSZ (File size limit exceeded)');compadd -S '' -d _comp_desc 'ABRT' 'ALRM' 'BUS' 'CHLD' 'CONT' 'FPE' 'HUP' 'ILL' 'INT' 'KILL' 'PIPE' 'POLL' 'PROF' 'PWR' 'QUIT' 'SEGV' 'STKFLT' 'STOP' 'SYS' 'TERM' 'TRAP' 'TSTP' 'TTIN' 'TTOU' 'URG' 'USR1' 'USR2' 'VTALRM' 'WINCH' 'XCPU' 'XFSZ'}" \
"(-m --message)"{-m,--message}"[message flag]: :{local _comp_desc=('_' 'ERR (message example)');compadd -S '' -d _comp_desc '_' 'ERR'}" \
"(-n --net_interfaces)"{-n,--net_interfaces}"[net_interfaces flag]: :_example_callback '_example__action##net_interfaces'" \
"(-n --net_interfaces)"{-n,--net_interfaces}"[net_interfaces flag]: :{_example_callback '_example__action##net_interfaces'}" \
"(-o --optarg)"{-o=-,--optarg=-}"[optional arg with default value blue]:: :{local _comp_desc=('blue' 'red' 'green' 'yellow');compadd -S '' -d _comp_desc 'blue' 'red' 'green' 'yellow'}" \
"--usergroup[user\:group flag]: :_example_callback '_example__action##usergroup'" \
"(-u --users)"{-u,--users}"[users flag]: :_example_callback '_example__action##users'" \
"--usergroup[user\:group flag]: :{_example_callback '_example__action##usergroup'}" \
"(-u --users)"{-u,--users}"[users flag]: :{_example_callback '_example__action##users'}" \
"(-v --values)"{-v,--values}"[values flag]: :{local _comp_desc=('values' 'example');compadd -S '' -d _comp_desc 'values' 'example'}" \
"(-d --values_described)"{-d,--values_described}"[values with description flag]: :{local _comp_desc=('values (valueDescription)' 'example (exampleDescription)');compadd -S '' -d _comp_desc 'values' 'example'}" \
"1: :{local _comp_desc=('positional1' 'p1');compadd -S '' -d _comp_desc 'positional1' 'p1'}" \
Expand All @@ -1308,16 +1308,16 @@ function _example__action {
function _example__callback {
_arguments -C \
"(-c --callback)"{-c,--callback}"[Help message for callback]: :_example_callback '_example__callback##callback'" \
"1: :_example_callback '_example__callback#1'" \
"2: :_example_callback '_example__callback#2'" \
"*: :_example_callback '_example__callback#0'"
"(-c --callback)"{-c,--callback}"[Help message for callback]: :{_example_callback '_example__callback##callback'}" \
"1: :{_example_callback '_example__callback#1'}" \
"2: :{_example_callback '_example__callback#2'}" \
"*: :{_example_callback '_example__callback#0'}"
}
function _example__condition {
_arguments -C \
"(-r --required)"{-r,--required}"[required flag]: :{local _comp_desc=('valid' 'invalid');compadd -S '' -d _comp_desc 'valid' 'invalid'}" \
"1: :_example_callback '_example__condition#1'"
"1: :{_example_callback '_example__condition#1'}"
}
function _example__help {
Expand All @@ -1340,14 +1340,14 @@ function _example__injection {
function _example__multiparts {
_arguments -C \
"--at[multiparts with @ as divider]: :_example_callback '_example__multiparts##at'" \
"--colon[multiparts with \: as divider ]: :_example_callback '_example__multiparts##colon'" \
"--comma[multiparts with , as divider]: :_example_callback '_example__multiparts##comma'" \
"--dot[multiparts with . as divider]: :_example_callback '_example__multiparts##dot'" \
"--dotdotdot[multiparts with ... as divider]: :_example_callback '_example__multiparts##dotdotdot'" \
"--equals[multiparts with = as divider]: :_example_callback '_example__multiparts##equals'" \
"--none[multiparts without divider]: :_example_callback '_example__multiparts##none'" \
"--slash[multiparts with / as divider]: :_example_callback '_example__multiparts##slash'" \
"--at[multiparts with @ as divider]: :{_example_callback '_example__multiparts##at'}" \
"--colon[multiparts with \: as divider ]: :{_example_callback '_example__multiparts##colon'}" \
"--comma[multiparts with , as divider]: :{_example_callback '_example__multiparts##comma'}" \
"--dot[multiparts with . as divider]: :{_example_callback '_example__multiparts##dot'}" \
"--dotdotdot[multiparts with ... as divider]: :{_example_callback '_example__multiparts##dotdotdot'}" \
"--equals[multiparts with = as divider]: :{_example_callback '_example__multiparts##equals'}" \
"--none[multiparts without divider]: :{_example_callback '_example__multiparts##none'}" \
"--slash[multiparts with / as divider]: :{_example_callback '_example__multiparts##slash'}" \
"*::arg:->args"
}
if compquote '' 2>/dev/null; then _example; else compdef _example example; fi
Expand Down
5 changes: 3 additions & 2 deletions fish/snippet.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ func snippetLazy(cmd *cobra.Command) string {
%v _carapace fish | source
complete --do-complete (commandline -cp)
end
complete --do-complete '%v ' > /dev/null
complete -c %v -e
complete -c %v -a '(_%v_completions)'
complete -c %v -f
`, cmd.Name(), cmd.Name(), uid.Executable(), cmd.Name(), cmd.Name(), cmd.Name())
`, cmd.Name(), cmd.Name(), uid.Executable(), cmd.Name(), cmd.Name(), cmd.Name(), cmd.Name())
}

func Snippet(cmd *cobra.Command, actions map[string]string, lazy bool) string {
Expand Down
2 changes: 1 addition & 1 deletion zsh/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func Sanitize(values ...string) []string {
}

func Callback(prefix string, cuid string) string {
return fmt.Sprintf(`_%v_callback '%v'`, prefix, cuid)
return fmt.Sprintf(`{_%v_callback '%v'}`, prefix, cuid)
}

func ActionDirectories() string {
Expand Down
2 changes: 1 addition & 1 deletion zsh/snippet.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func Snippet(cmd *cobra.Command, actions map[string]string, lazy bool) string {
result := fmt.Sprintf("#compdef %v\n", cmd.Name())
result += fmt.Sprintf(`function _%v_callback {
# shellcheck disable=SC2086
eval "$(%v _carapace zsh "$5" ${os_args})"
eval "$(%v _carapace zsh "$1" ${os_args})"
}
`, cmd.Name(), uid.Executable())
result += snippetFunctions(cmd, actions)
Expand Down

0 comments on commit b1194c1

Please sign in to comment.