Skip to content

Commit

Permalink
Treat ValidArgsFunction similarly to ValidArgs
Browse files Browse the repository at this point in the history
This change is to have ValidArgsFunction behave like ValidArgs
specifically for the case where a command has ValidArgsFunction and also
has sub-commands.  To mimic ValidArgs, ValidArgsFunction will take
precedence over sub-commands during completion.

Signed-off-by: Marc Khouzam <marc.khouzam@montreal.ca>
  • Loading branch information
marckhouzam committed Apr 3, 2020
1 parent 7b6f441 commit ed9b65c
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions bash_completions.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,10 @@ __%[1]s_handle_reply()
completions=("${commands[@]}")
if [[ ${#must_have_one_noun[@]} -ne 0 ]]; then
completions=("${must_have_one_noun[@]}")
elif [[ -n "${has_completion_function}" ]]; then
# if a go completion function is provided, defer to that function
completions=()
__%[1]s_handle_go_custom_completion
fi
if [[ ${#must_have_one_flag[@]} -ne 0 ]]; then
completions+=("${must_have_one_flag[@]}")
Expand All @@ -197,18 +201,13 @@ __%[1]s_handle_reply()
fi
if [[ ${#COMPREPLY[@]} -eq 0 ]]; then
# if a go completion function is provided, defer to that function
if [ -n "${has_completion_function}" ]; then
__%[1]s_handle_go_custom_completion
else
if declare -F __%[1]s_custom_func >/dev/null; then
# try command name qualified custom func
__%[1]s_custom_func
else
# otherwise fall back to unqualified for compatibility
declare -F __custom_func >/dev/null && __custom_func
fi
fi
if declare -F __%[1]s_custom_func >/dev/null; then
# try command name qualified custom func
__%[1]s_custom_func
else
# otherwise fall back to unqualified for compatibility
declare -F __custom_func >/dev/null && __custom_func
fi
fi
# available in bash-completion >= 2, not always present on macOS
Expand Down

0 comments on commit ed9b65c

Please sign in to comment.