Skip to content

Commit

Permalink
Update tests to pass
Browse files Browse the repository at this point in the history
  • Loading branch information
jsotuyod authored and remkop committed Oct 31, 2022
1 parent b946871 commit 176de2c
Show file tree
Hide file tree
Showing 6 changed files with 349 additions and 54 deletions.
140 changes: 140 additions & 0 deletions src/test/java/picocli/AutoCompleteTest.java
Expand Up @@ -756,6 +756,41 @@ private String expectedCompletionScriptForAutoCompleteApp() {
" echo \"$result\"\n" +
"}\n" +
"\n" +
"# compReplyArray generates a list of completion suggestions based on an array, ensuring all values are properly escaped.\n" +
"#\n" +
"# compReplyArray takes a single parameter: the array of options to be displayed\n" +
"#\n" +
"# The output is echoed to std_out, one option per line.\n" +
"#\n" +
"# Example usage:\n" +
"# local options=(\"foo\", \"bar\", \"baz\")\n" +
"# local IFS=$'\\n'\n" +
"# COMPREPLY=$(compReplyArray \"${options[@]}\")\n" +
"function compReplyArray() {\n" +
" declare -a options\n" +
" options=(\"$@\")\n" +
" local curr_word=${COMP_WORDS[COMP_CWORD]}\n" +
" local i\n" +
" local quoted\n" +
" local optionList=()\n" +
"\n" +
" for (( i=0; i<${#options[@]}; i++ )); do\n" +
" # Double escape, since we want escaped values, but compgen -W expands the argument\n" +
" printf -v quoted %%q \"${options[i]}\"\n" +
" quoted=\\'${quoted//\\'/\\'\\\\\\'\\'}\\'\n" +
"\n" +
" optionList[i]=$quoted\n" +
" done\n" +
"\n" +
" # We also have to add another round of escaping to $curr_word.\n" +
" curr_word=${curr_word//\\\\/\\\\\\\\}\n" +
" curr_word=${curr_word//\\'/\\\\\\'}\n" +
"\n" +
" # Actually generate completions.\n" +
" local IFS=$'\\n'\n" +
" echo -e \"$(compgen -W \"${optionList[*]}\" -- \"$curr_word\")\"\n" +
"}\n" +
"\n" +
"# Bash completion entry point function.\n" +
"# _complete_picocli.AutoComplete finds which commands and subcommands have been specified\n" +
"# on the command line and delegates to the appropriate function\n" +
Expand Down Expand Up @@ -974,6 +1009,41 @@ private String expectedCompletionScriptForNonDefault() {
" echo \"$result\"\n" +
"}\n" +
"\n" +
"# compReplyArray generates a list of completion suggestions based on an array, ensuring all values are properly escaped.\n" +
"#\n" +
"# compReplyArray takes a single parameter: the array of options to be displayed\n" +
"#\n" +
"# The output is echoed to std_out, one option per line.\n" +
"#\n" +
"# Example usage:\n" +
"# local options=(\"foo\", \"bar\", \"baz\")\n" +
"# local IFS=$'\\n'\n" +
"# COMPREPLY=$(compReplyArray \"${options[@]}\")\n" +
"function compReplyArray() {\n" +
" declare -a options\n" +
" options=(\"$@\")\n" +
" local curr_word=${COMP_WORDS[COMP_CWORD]}\n" +
" local i\n" +
" local quoted\n" +
" local optionList=()\n" +
"\n" +
" for (( i=0; i<${#options[@]}; i++ )); do\n" +
" # Double escape, since we want escaped values, but compgen -W expands the argument\n" +
" printf -v quoted %%q \"${options[i]}\"\n" +
" quoted=\\'${quoted//\\'/\\'\\\\\\'\\'}\\'\n" +
"\n" +
" optionList[i]=$quoted\n" +
" done\n" +
"\n" +
" # We also have to add another round of escaping to $curr_word.\n" +
" curr_word=${curr_word//\\\\/\\\\\\\\}\n" +
" curr_word=${curr_word//\\'/\\\\\\'}\n" +
"\n" +
" # Actually generate completions.\n" +
" local IFS=$'\\n'\n" +
" echo -e \"$(compgen -W \"${optionList[*]}\" -- \"$curr_word\")\"\n" +
"}\n" +
"\n" +
"# Bash completion entry point function.\n" +
"# _complete_nondefault finds which commands and subcommands have been specified\n" +
"# on the command line and delegates to the appropriate function\n" +
Expand Down Expand Up @@ -1540,6 +1610,41 @@ private String getCompletionScriptText(String cmdName) {
" echo \"$result\"\n" +
"}\n" +
"\n" +
"# compReplyArray generates a list of completion suggestions based on an array, ensuring all values are properly escaped.\n" +
"#\n" +
"# compReplyArray takes a single parameter: the array of options to be displayed\n" +
"#\n" +
"# The output is echoed to std_out, one option per line.\n" +
"#\n" +
"# Example usage:\n" +
"# local options=(\"foo\", \"bar\", \"baz\")\n" +
"# local IFS=$'\\n'\n" +
"# COMPREPLY=$(compReplyArray \"${options[@]}\")\n" +
"function compReplyArray() {\n" +
" declare -a options\n" +
" options=(\"$@\")\n" +
" local curr_word=${COMP_WORDS[COMP_CWORD]}\n" +
" local i\n" +
" local quoted\n" +
" local optionList=()\n" +
"\n" +
" for (( i=0; i<${#options[@]}; i++ )); do\n" +
" # Double escape, since we want escaped values, but compgen -W expands the argument\n" +
" printf -v quoted %%q \"${options[i]}\"\n" +
" quoted=\\'${quoted//\\'/\\'\\\\\\'\\'}\\'\n" +
"\n" +
" optionList[i]=$quoted\n" +
" done\n" +
"\n" +
" # We also have to add another round of escaping to $curr_word.\n" +
" curr_word=${curr_word//\\\\/\\\\\\\\}\n" +
" curr_word=${curr_word//\\'/\\\\\\'}\n" +
"\n" +
" # Actually generate completions.\n" +
" local IFS=$'\\n'\n" +
" echo -e \"$(compgen -W \"${optionList[*]}\" -- \"$curr_word\")\"\n" +
"}\n" +
"\n" +
"# Bash completion entry point function.\n" +
"# _complete_%1$s finds which commands and subcommands have been specified\n" +
"# on the command line and delegates to the appropriate function\n" +
Expand Down Expand Up @@ -1752,6 +1857,41 @@ private String getCompletionScriptTextWithHidden(String commandName) {
" echo \"$result\"\n" +
"}\n" +
"\n" +
"# compReplyArray generates a list of completion suggestions based on an array, ensuring all values are properly escaped.\n" +
"#\n" +
"# compReplyArray takes a single parameter: the array of options to be displayed\n" +
"#\n" +
"# The output is echoed to std_out, one option per line.\n" +
"#\n" +
"# Example usage:\n" +
"# local options=(\"foo\", \"bar\", \"baz\")\n" +
"# local IFS=$'\\n'\n" +
"# COMPREPLY=$(compReplyArray \"${options[@]}\")\n" +
"function compReplyArray() {\n" +
" declare -a options\n" +
" options=(\"$@\")\n" +
" local curr_word=${COMP_WORDS[COMP_CWORD]}\n" +
" local i\n" +
" local quoted\n" +
" local optionList=()\n" +
"\n" +
" for (( i=0; i<${#options[@]}; i++ )); do\n" +
" # Double escape, since we want escaped values, but compgen -W expands the argument\n" +
" printf -v quoted %%q \"${options[i]}\"\n" +
" quoted=\\'${quoted//\\'/\\'\\\\\\'\\'}\\'\n" +
"\n" +
" optionList[i]=$quoted\n" +
" done\n" +
"\n" +
" # We also have to add another round of escaping to $curr_word.\n" +
" curr_word=${curr_word//\\\\/\\\\\\\\}\n" +
" curr_word=${curr_word//\\'/\\\\\\'}\n" +
"\n" +
" # Actually generate completions.\n" +
" local IFS=$'\\n'\n" +
" echo -e \"$(compgen -W \"${optionList[*]}\" -- \"$curr_word\")\"\n" +
"}\n" +
"\n" +
"# Bash completion entry point function.\n" +
"# _complete_%1$s finds which commands and subcommands have been specified\n" +
"# on the command line and delegates to the appropriate function\n" +
Expand Down
37 changes: 36 additions & 1 deletion src/test/resources/bashify_completion.bash
Expand Up @@ -113,6 +113,41 @@ function currentPositionalIndex() {
echo "$result"
}

# compReplyArray generates a list of completion suggestions based on an array, ensuring all values are properly escaped.
#
# compReplyArray takes a single parameter: the array of options to be displayed
#
# The output is echoed to std_out, one option per line.
#
# Example usage:
# local options=("foo", "bar", "baz")
# local IFS=$'\n'
# COMPREPLY=$(compReplyArray "${options[@]}")
function compReplyArray() {
declare -a options
options=("$@")
local curr_word=${COMP_WORDS[COMP_CWORD]}
local i
local quoted
local optionList=()

for (( i=0; i<${#options[@]}; i++ )); do
# Double escape, since we want escaped values, but compgen -W expands the argument
printf -v quoted %%q "${options[i]}"
quoted=\'${quoted//\'/\'\\\'\'}\'

optionList[i]=$quoted
done

# We also have to add another round of escaping to $curr_word.
curr_word=${curr_word//\\/\\\\}
curr_word=${curr_word//\'/\\\'}

# Actually generate completions.
local IFS=$'\n'
echo -e "$(compgen -W "${optionList[*]}" -- "$curr_word")"
}

# Bash completion entry point function.
# _complete_bashify finds which commands and subcommands have been specified
# on the command line and delegates to the appropriate function
Expand Down Expand Up @@ -143,7 +178,7 @@ function _picocli_bashify() {
case ${prev_word} in
-x)
local IFS=$'\n'
COMPREPLY=( $( compgen -W "${_AB_C_option_args[*]}" -- "${curr_word}" ) )
COMPREPLY=( $( compReplyArray "${_AB_C_option_args[@]}" ) )
return $?
;;
esac
Expand Down
37 changes: 36 additions & 1 deletion src/test/resources/basic.bash
Expand Up @@ -113,6 +113,41 @@ function currentPositionalIndex() {
echo "$result"
}

# compReplyArray generates a list of completion suggestions based on an array, ensuring all values are properly escaped.
#
# compReplyArray takes a single parameter: the array of options to be displayed
#
# The output is echoed to std_out, one option per line.
#
# Example usage:
# local options=("foo", "bar", "baz")
# local IFS=$'\n'
# COMPREPLY=$(compReplyArray "${options[@]}")
function compReplyArray() {
declare -a options
options=("$@")
local curr_word=${COMP_WORDS[COMP_CWORD]}
local i
local quoted
local optionList=()

for (( i=0; i<${#options[@]}; i++ )); do
# Double escape, since we want escaped values, but compgen -W expands the argument
printf -v quoted %%q "${options[i]}"
quoted=\'${quoted//\'/\'\\\'\'}\'

optionList[i]=$quoted
done

# We also have to add another round of escaping to $curr_word.
curr_word=${curr_word//\\/\\\\}
curr_word=${curr_word//\'/\\\'}

# Actually generate completions.
local IFS=$'\n'
echo -e "$(compgen -W "${optionList[*]}" -- "$curr_word")"
}

# Bash completion entry point function.
# _complete_basicExample finds which commands and subcommands have been specified
# on the command line and delegates to the appropriate function
Expand Down Expand Up @@ -143,7 +178,7 @@ function _picocli_basicExample() {
case ${prev_word} in
-u|--timeUnit)
local IFS=$'\n'
COMPREPLY=( $( compgen -W "${timeUnit_option_args[*]}" -- "${curr_word}" ) )
COMPREPLY=( $( compReplyArray "${timeUnit_option_args[@]}" ) )
return $?
;;
-t|--timeout)
Expand Down
35 changes: 35 additions & 0 deletions src/test/resources/hyphenated_completion.bash
Expand Up @@ -113,6 +113,41 @@ function currentPositionalIndex() {
echo "$result"
}

# compReplyArray generates a list of completion suggestions based on an array, ensuring all values are properly escaped.
#
# compReplyArray takes a single parameter: the array of options to be displayed
#
# The output is echoed to std_out, one option per line.
#
# Example usage:
# local options=("foo", "bar", "baz")
# local IFS=$'\n'
# COMPREPLY=$(compReplyArray "${options[@]}")
function compReplyArray() {
declare -a options
options=("$@")
local curr_word=${COMP_WORDS[COMP_CWORD]}
local i
local quoted
local optionList=()

for (( i=0; i<${#options[@]}; i++ )); do
# Double escape, since we want escaped values, but compgen -W expands the argument
printf -v quoted %%q "${options[i]}"
quoted=\'${quoted//\'/\'\\\'\'}\'

optionList[i]=$quoted
done

# We also have to add another round of escaping to $curr_word.
curr_word=${curr_word//\\/\\\\}
curr_word=${curr_word//\'/\\\'}

# Actually generate completions.
local IFS=$'\n'
echo -e "$(compgen -W "${optionList[*]}" -- "$curr_word")"
}

# Bash completion entry point function.
# _complete_rcmd finds which commands and subcommands have been specified
# on the command line and delegates to the appropriate function
Expand Down

0 comments on commit 176de2c

Please sign in to comment.