diff --git a/src/main/java/picocli/AutoComplete.java b/src/main/java/picocli/AutoComplete.java index 5e8fa650f..60d288630 100644 --- a/src/main/java/picocli/AutoComplete.java +++ b/src/main/java/picocli/AutoComplete.java @@ -715,16 +715,16 @@ private static String generateFunctionForCommand(String functionName, String com private static void generatePositionParamCompletionCandidates(StringBuilder buff, PositionalParamSpec f) { String paramName = bashify(f.paramLabel()); - buff.append(format(" local %s_pos_param_args=\"%s\" # %d-%d values\n", + buff.append(format(" local %s_pos_param_args=(\"%s\") # %d-%d values\n", paramName, - concat(" ", extract(f.completionCandidates())).trim(), + concat("\" \"", extract(f.completionCandidates())).trim(), f.index().min(), f.index().max())); } private static void generateCompletionCandidates(StringBuilder buff, OptionSpec f) { - buff.append(format(" local %s_option_args=\"%s\" # %s values\n", + buff.append(format(" local %s_option_args=(\"%s\") # %s values\n", bashify(f.paramLabel()), - concat(" ", extract(f.completionCandidates())).trim(), + concat("\" \"", extract(f.completionCandidates())).trim(), f.longestName())); } private static List extract(Iterable generator) { @@ -749,7 +749,9 @@ private static String generatePositionalParamsCases(List po int max = param.index().max(); if (param.completionCandidates() != null) { buff.append(format("%s %s (( currIndex >= %d && currIndex <= %d )); then\n", indent, ifOrElif, min, max)); - buff.append(format("%s positionals=$( compgen -W \"$%s_pos_param_args\" -- \"%s\" )\n", indent, paramName, currWord)); + buff.append(format("%s local IFS=$'\\n'\n", indent)); + buff.append(format("%s positionals=$( compgen -W \"${%s_pos_param_args[*]}\" -- \"%s\" )\n", + indent, paramName, currWord)); } else if (type.equals(File.class) || "java.nio.file.Path".equals(type.getName())) { buff.append(format("%s %s (( currIndex >= %d && currIndex <= %d )); then\n", indent, ifOrElif, min, max)); buff.append(format("%s local IFS=$'\\n'\n", indent)); @@ -792,7 +794,9 @@ private static String generateOptionsCases(List argOptionFields, Str } if (option.completionCandidates() != null) { buff.append(format("%s %s)\n", indent, concat("|", option.names()))); // " -u|--timeUnit)\n" - buff.append(format("%s COMPREPLY=( $( compgen -W \"${%s_option_args}\" -- \"%s\" ) )\n", indent, bashify(option.paramLabel()), currWord)); + buff.append(format("%s local IFS=$'\\n'\n", indent)); + buff.append(format("%s COMPREPLY=( $( compgen -W \"${%s_option_args[*]}\" -- \"%s\" ) )\n", indent, + bashify(option.paramLabel()), currWord)); buff.append(format("%s return $?\n", indent)); buff.append(format("%s ;;\n", indent)); } else if (type.equals(File.class) || "java.nio.file.Path".equals(type.getName())) { diff --git a/src/test/java/picocli/AutoCompleteTest.java b/src/test/java/picocli/AutoCompleteTest.java index 8546ed074..ede423df5 100644 --- a/src/test/java/picocli/AutoCompleteTest.java +++ b/src/test/java/picocli/AutoCompleteTest.java @@ -15,22 +15,15 @@ */ package picocli; -import org.hamcrest.MatcherAssert; -import org.junit.Rule; -import org.junit.Test; -import org.junit.contrib.java.lang.system.Assertion; -import org.junit.contrib.java.lang.system.ExpectedSystemExit; -import org.junit.contrib.java.lang.system.ProvideSystemProperty; -import org.junit.contrib.java.lang.system.RestoreSystemProperties; -import org.junit.contrib.java.lang.system.SystemErrRule; -import org.junit.contrib.java.lang.system.SystemOutRule; -import org.junit.rules.TestRule; -import picocli.CommandLine.Command; -import picocli.CommandLine.Model.CommandSpec; -import picocli.CommandLine.Model.OptionSpec; -import picocli.CommandLine.Model.PositionalParamSpec; -import picocli.CommandLine.Option; -import picocli.CommandLine.Parameters; +import static java.lang.String.format; +import static org.hamcrest.CoreMatchers.containsString; +import static org.hamcrest.CoreMatchers.not; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; import java.io.BufferedReader; import java.io.File; @@ -53,11 +46,23 @@ import java.util.Scanner; import java.util.concurrent.TimeUnit; -import static java.lang.String.format; -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.CoreMatchers.not; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.junit.Assert.*; +import org.hamcrest.MatcherAssert; +import org.junit.Rule; +import org.junit.Test; +import org.junit.contrib.java.lang.system.Assertion; +import org.junit.contrib.java.lang.system.ExpectedSystemExit; +import org.junit.contrib.java.lang.system.ProvideSystemProperty; +import org.junit.contrib.java.lang.system.RestoreSystemProperties; +import org.junit.contrib.java.lang.system.SystemErrRule; +import org.junit.contrib.java.lang.system.SystemOutRule; +import org.junit.rules.TestRule; + +import picocli.CommandLine.Command; +import picocli.CommandLine.Model.CommandSpec; +import picocli.CommandLine.Model.OptionSpec; +import picocli.CommandLine.Model.PositionalParamSpec; +import picocli.CommandLine.Option; +import picocli.CommandLine.Parameters; /** * Tests the scripts generated by AutoComplete. @@ -93,7 +98,7 @@ public void run() { public void basic() throws Exception { String script = AutoComplete.bash("basicExample", new CommandLine(new BasicExample())); String expected = format(loadTextFromClasspath("/basic.bash"), - CommandLine.VERSION, spaced(TimeUnit.values())); + CommandLine.VERSION, concat("\" \"", TimeUnit.values())); assertEquals(expected, script); } @@ -188,7 +193,7 @@ public void nestedSubcommands() throws Exception { ); String script = AutoComplete.bash("picocompletion-demo", hierarchy); String expected = format(loadTextFromClasspath("/picocompletion-demo_completion.bash"), - CommandLine.VERSION, spaced(TimeUnit.values())); + CommandLine.VERSION, concat("\" \"", TimeUnit.values())); assertEquals(expected, script); } @@ -204,16 +209,16 @@ public void helpCommand() { .addSubcommand(new CommandLine.HelpCommand()); String script = AutoComplete.bash("picocompletion-demo-help", hierarchy); String expected = format(loadTextFromClasspath("/picocompletion-demo-help_completion.bash"), - CommandLine.VERSION, spaced(TimeUnit.values())); + CommandLine.VERSION, concat("\" \"", TimeUnit.values())); assertEquals(expected, script); } - private static String spaced(Object[] values) { + private static String concat(String infix, Object[] values) { StringBuilder result = new StringBuilder(); for (Object value : values) { - result.append(value).append(' '); + result.append(value).append(infix); } - return result.toString().substring(0, result.length() - 1); + return result.toString().substring(0, result.length() - infix.length()); } static String loadTextFromClasspath(String path) { diff --git a/src/test/resources/bashify_completion.bash b/src/test/resources/bashify_completion.bash index 679c78656..c0a5cebe8 100644 --- a/src/test/resources/bashify_completion.bash +++ b/src/test/resources/bashify_completion.bash @@ -136,13 +136,14 @@ function _picocli_bashify() { local commands="" local flag_opts="" local arg_opts="-x" - local _AB_C_option_args="1" # -x values + local _AB_C_option_args=("1") # -x values type compopt &>/dev/null && compopt +o default case ${prev_word} in -x) - COMPREPLY=( $( compgen -W "${_AB_C_option_args}" -- "${curr_word}" ) ) + local IFS=$'\n' + COMPREPLY=( $( compgen -W "${_AB_C_option_args[*]}" -- "${curr_word}" ) ) return $? ;; esac diff --git a/src/test/resources/basic.bash b/src/test/resources/basic.bash index ce12421b9..8bc3d0d16 100644 --- a/src/test/resources/basic.bash +++ b/src/test/resources/basic.bash @@ -136,13 +136,14 @@ function _picocli_basicExample() { local commands="" local flag_opts="" local arg_opts="-u --timeUnit -t --timeout" - local timeUnit_option_args="%2$s" # --timeUnit values + local timeUnit_option_args=("%2$s") # --timeUnit values type compopt &>/dev/null && compopt +o default case ${prev_word} in -u|--timeUnit) - COMPREPLY=( $( compgen -W "${timeUnit_option_args}" -- "${curr_word}" ) ) + local IFS=$'\n' + COMPREPLY=( $( compgen -W "${timeUnit_option_args[*]}" -- "${curr_word}" ) ) return $? ;; -t|--timeout) diff --git a/src/test/resources/picocompletion-demo-help_completion.bash b/src/test/resources/picocompletion-demo-help_completion.bash index 3408e5681..d63a12a53 100644 --- a/src/test/resources/picocompletion-demo-help_completion.bash +++ b/src/test/resources/picocompletion-demo-help_completion.bash @@ -204,7 +204,7 @@ function _picocli_picocompletion-demo-help_sub1() { local commands="" local flag_opts="" local arg_opts="--num --str --candidates" - local str2_option_args="aaa bbb ccc" # --candidates values + local str2_option_args=("aaa" "bbb" "ccc") # --candidates values type compopt &>/dev/null && compopt +o default @@ -216,7 +216,8 @@ function _picocli_picocompletion-demo-help_sub1() { return ;; --candidates) - COMPREPLY=( $( compgen -W "${str2_option_args}" -- "${curr_word}" ) ) + local IFS=$'\n' + COMPREPLY=( $( compgen -W "${str2_option_args[*]}" -- "${curr_word}" ) ) return $? ;; esac @@ -238,7 +239,7 @@ function _picocli_picocompletion-demo-help_sub1alias() { local commands="" local flag_opts="" local arg_opts="--num --str --candidates" - local str2_option_args="aaa bbb ccc" # --candidates values + local str2_option_args=("aaa" "bbb" "ccc") # --candidates values type compopt &>/dev/null && compopt +o default @@ -250,7 +251,8 @@ function _picocli_picocompletion-demo-help_sub1alias() { return ;; --candidates) - COMPREPLY=( $( compgen -W "${str2_option_args}" -- "${curr_word}" ) ) + local IFS=$'\n' + COMPREPLY=( $( compgen -W "${str2_option_args[*]}" -- "${curr_word}" ) ) return $? ;; esac @@ -286,7 +288,7 @@ function _picocli_picocompletion-demo-help_sub2() { return $? ;; esac - local possibilities_pos_param_args="Aaa Bbb Ccc" # 0-0 values + local possibilities_pos_param_args=("Aaa" "Bbb" "Ccc") # 0-0 values if [[ "${curr_word}" == -* ]]; then COMPREPLY=( $(compgen -W "${flag_opts} ${arg_opts}" -- "${curr_word}") ) @@ -295,7 +297,8 @@ function _picocli_picocompletion-demo-help_sub2() { local currIndex currIndex=$(currentPositionalIndex "sub2" "${arg_opts}" "${flag_opts}") if (( currIndex >= 0 && currIndex <= 0 )); then - positionals=$( compgen -W "$possibilities_pos_param_args" -- "${curr_word}" ) + local IFS=$'\n' + positionals=$( compgen -W "${possibilities_pos_param_args[*]}" -- "${curr_word}" ) fi COMPREPLY=( $(compgen -W "${commands} ${positionals}" -- "${curr_word}") ) fi @@ -324,7 +327,7 @@ function _picocli_picocompletion-demo-help_sub2alias() { return $? ;; esac - local possibilities_pos_param_args="Aaa Bbb Ccc" # 0-0 values + local possibilities_pos_param_args=("Aaa" "Bbb" "Ccc") # 0-0 values if [[ "${curr_word}" == -* ]]; then COMPREPLY=( $(compgen -W "${flag_opts} ${arg_opts}" -- "${curr_word}") ) @@ -333,7 +336,8 @@ function _picocli_picocompletion-demo-help_sub2alias() { local currIndex currIndex=$(currentPositionalIndex "sub2-alias" "${arg_opts}" "${flag_opts}") if (( currIndex >= 0 && currIndex <= 0 )); then - positionals=$( compgen -W "$possibilities_pos_param_args" -- "${curr_word}" ) + local IFS=$'\n' + positionals=$( compgen -W "${possibilities_pos_param_args[*]}" -- "${curr_word}" ) fi COMPREPLY=( $(compgen -W "${commands} ${positionals}" -- "${curr_word}") ) fi @@ -421,20 +425,21 @@ function _picocli_picocompletion-demo-help_sub2_subsub2() { local commands="" local flag_opts="" local arg_opts="-u --timeUnit -t --timeout" - local timeUnit_option_args="%2$s" # --timeUnit values + local timeUnit_option_args=("%2$s") # --timeUnit values type compopt &>/dev/null && compopt +o default case ${prev_word} in -u|--timeUnit) - COMPREPLY=( $( compgen -W "${timeUnit_option_args}" -- "${curr_word}" ) ) + local IFS=$'\n' + COMPREPLY=( $( compgen -W "${timeUnit_option_args[*]}" -- "${curr_word}" ) ) return $? ;; -t|--timeout) return ;; esac - local str2_pos_param_args="aaa bbb ccc" # 0-0 values + local str2_pos_param_args=("aaa" "bbb" "ccc") # 0-0 values if [[ "${curr_word}" == -* ]]; then COMPREPLY=( $(compgen -W "${flag_opts} ${arg_opts}" -- "${curr_word}") ) @@ -443,7 +448,8 @@ function _picocli_picocompletion-demo-help_sub2_subsub2() { local currIndex currIndex=$(currentPositionalIndex "subsub2" "${arg_opts}" "${flag_opts}") if (( currIndex >= 0 && currIndex <= 0 )); then - positionals=$( compgen -W "$str2_pos_param_args" -- "${curr_word}" ) + local IFS=$'\n' + positionals=$( compgen -W "${str2_pos_param_args[*]}" -- "${curr_word}" ) fi COMPREPLY=( $(compgen -W "${commands} ${positionals}" -- "${curr_word}") ) fi @@ -458,20 +464,21 @@ function _picocli_picocompletion-demo-help_sub2_sub2child2alias() { local commands="" local flag_opts="" local arg_opts="-u --timeUnit -t --timeout" - local timeUnit_option_args="%2$s" # --timeUnit values + local timeUnit_option_args=("%2$s") # --timeUnit values type compopt &>/dev/null && compopt +o default case ${prev_word} in -u|--timeUnit) - COMPREPLY=( $( compgen -W "${timeUnit_option_args}" -- "${curr_word}" ) ) + local IFS=$'\n' + COMPREPLY=( $( compgen -W "${timeUnit_option_args[*]}" -- "${curr_word}" ) ) return $? ;; -t|--timeout) return ;; esac - local str2_pos_param_args="aaa bbb ccc" # 0-0 values + local str2_pos_param_args=("aaa" "bbb" "ccc") # 0-0 values if [[ "${curr_word}" == -* ]]; then COMPREPLY=( $(compgen -W "${flag_opts} ${arg_opts}" -- "${curr_word}") ) @@ -480,7 +487,8 @@ function _picocli_picocompletion-demo-help_sub2_sub2child2alias() { local currIndex currIndex=$(currentPositionalIndex "sub2child2-alias" "${arg_opts}" "${flag_opts}") if (( currIndex >= 0 && currIndex <= 0 )); then - positionals=$( compgen -W "$str2_pos_param_args" -- "${curr_word}" ) + local IFS=$'\n' + positionals=$( compgen -W "${str2_pos_param_args[*]}" -- "${curr_word}" ) fi COMPREPLY=( $(compgen -W "${commands} ${positionals}" -- "${curr_word}") ) fi @@ -494,7 +502,7 @@ function _picocli_picocompletion-demo-help_sub2_subsub3() { local commands="" local flag_opts="" local arg_opts="" - local cands_pos_param_args="aaa bbb ccc" # 0-0 values + local cands_pos_param_args=("aaa" "bbb" "ccc") # 0-0 values if [[ "${curr_word}" == -* ]]; then COMPREPLY=( $(compgen -W "${flag_opts} ${arg_opts}" -- "${curr_word}") ) @@ -503,7 +511,8 @@ function _picocli_picocompletion-demo-help_sub2_subsub3() { local currIndex currIndex=$(currentPositionalIndex "subsub3" "${arg_opts}" "${flag_opts}") if (( currIndex >= 0 && currIndex <= 0 )); then - positionals=$( compgen -W "$cands_pos_param_args" -- "${curr_word}" ) + local IFS=$'\n' + positionals=$( compgen -W "${cands_pos_param_args[*]}" -- "${curr_word}" ) elif (( currIndex >= 1 && currIndex <= 2 )); then local IFS=$'\n' type compopt &>/dev/null && compopt -o filenames @@ -524,7 +533,7 @@ function _picocli_picocompletion-demo-help_sub2_sub2child3alias() { local commands="" local flag_opts="" local arg_opts="" - local cands_pos_param_args="aaa bbb ccc" # 0-0 values + local cands_pos_param_args=("aaa" "bbb" "ccc") # 0-0 values if [[ "${curr_word}" == -* ]]; then COMPREPLY=( $(compgen -W "${flag_opts} ${arg_opts}" -- "${curr_word}") ) @@ -533,7 +542,8 @@ function _picocli_picocompletion-demo-help_sub2_sub2child3alias() { local currIndex currIndex=$(currentPositionalIndex "sub2child3-alias" "${arg_opts}" "${flag_opts}") if (( currIndex >= 0 && currIndex <= 0 )); then - positionals=$( compgen -W "$cands_pos_param_args" -- "${curr_word}" ) + local IFS=$'\n' + positionals=$( compgen -W "${cands_pos_param_args[*]}" -- "${curr_word}" ) elif (( currIndex >= 1 && currIndex <= 2 )); then local IFS=$'\n' type compopt &>/dev/null && compopt -o filenames @@ -611,20 +621,21 @@ function _picocli_picocompletion-demo-help_sub2alias_subsub2() { local commands="" local flag_opts="" local arg_opts="-u --timeUnit -t --timeout" - local timeUnit_option_args="%2$s" # --timeUnit values + local timeUnit_option_args=("%2$s") # --timeUnit values type compopt &>/dev/null && compopt +o default case ${prev_word} in -u|--timeUnit) - COMPREPLY=( $( compgen -W "${timeUnit_option_args}" -- "${curr_word}" ) ) + local IFS=$'\n' + COMPREPLY=( $( compgen -W "${timeUnit_option_args[*]}" -- "${curr_word}" ) ) return $? ;; -t|--timeout) return ;; esac - local str2_pos_param_args="aaa bbb ccc" # 0-0 values + local str2_pos_param_args=("aaa" "bbb" "ccc") # 0-0 values if [[ "${curr_word}" == -* ]]; then COMPREPLY=( $(compgen -W "${flag_opts} ${arg_opts}" -- "${curr_word}") ) @@ -633,7 +644,8 @@ function _picocli_picocompletion-demo-help_sub2alias_subsub2() { local currIndex currIndex=$(currentPositionalIndex "subsub2" "${arg_opts}" "${flag_opts}") if (( currIndex >= 0 && currIndex <= 0 )); then - positionals=$( compgen -W "$str2_pos_param_args" -- "${curr_word}" ) + local IFS=$'\n' + positionals=$( compgen -W "${str2_pos_param_args[*]}" -- "${curr_word}" ) fi COMPREPLY=( $(compgen -W "${commands} ${positionals}" -- "${curr_word}") ) fi @@ -648,20 +660,21 @@ function _picocli_picocompletion-demo-help_sub2alias_sub2child2alias() { local commands="" local flag_opts="" local arg_opts="-u --timeUnit -t --timeout" - local timeUnit_option_args="%2$s" # --timeUnit values + local timeUnit_option_args=("%2$s") # --timeUnit values type compopt &>/dev/null && compopt +o default case ${prev_word} in -u|--timeUnit) - COMPREPLY=( $( compgen -W "${timeUnit_option_args}" -- "${curr_word}" ) ) + local IFS=$'\n' + COMPREPLY=( $( compgen -W "${timeUnit_option_args[*]}" -- "${curr_word}" ) ) return $? ;; -t|--timeout) return ;; esac - local str2_pos_param_args="aaa bbb ccc" # 0-0 values + local str2_pos_param_args=("aaa" "bbb" "ccc") # 0-0 values if [[ "${curr_word}" == -* ]]; then COMPREPLY=( $(compgen -W "${flag_opts} ${arg_opts}" -- "${curr_word}") ) @@ -670,7 +683,8 @@ function _picocli_picocompletion-demo-help_sub2alias_sub2child2alias() { local currIndex currIndex=$(currentPositionalIndex "sub2child2-alias" "${arg_opts}" "${flag_opts}") if (( currIndex >= 0 && currIndex <= 0 )); then - positionals=$( compgen -W "$str2_pos_param_args" -- "${curr_word}" ) + local IFS=$'\n' + positionals=$( compgen -W "${str2_pos_param_args[*]}" -- "${curr_word}" ) fi COMPREPLY=( $(compgen -W "${commands} ${positionals}" -- "${curr_word}") ) fi @@ -684,7 +698,7 @@ function _picocli_picocompletion-demo-help_sub2alias_subsub3() { local commands="" local flag_opts="" local arg_opts="" - local cands_pos_param_args="aaa bbb ccc" # 0-0 values + local cands_pos_param_args=("aaa" "bbb" "ccc") # 0-0 values if [[ "${curr_word}" == -* ]]; then COMPREPLY=( $(compgen -W "${flag_opts} ${arg_opts}" -- "${curr_word}") ) @@ -693,7 +707,8 @@ function _picocli_picocompletion-demo-help_sub2alias_subsub3() { local currIndex currIndex=$(currentPositionalIndex "subsub3" "${arg_opts}" "${flag_opts}") if (( currIndex >= 0 && currIndex <= 0 )); then - positionals=$( compgen -W "$cands_pos_param_args" -- "${curr_word}" ) + local IFS=$'\n' + positionals=$( compgen -W "${cands_pos_param_args[*]}" -- "${curr_word}" ) elif (( currIndex >= 1 && currIndex <= 2 )); then local IFS=$'\n' type compopt &>/dev/null && compopt -o filenames @@ -714,7 +729,7 @@ function _picocli_picocompletion-demo-help_sub2alias_sub2child3alias() { local commands="" local flag_opts="" local arg_opts="" - local cands_pos_param_args="aaa bbb ccc" # 0-0 values + local cands_pos_param_args=("aaa" "bbb" "ccc") # 0-0 values if [[ "${curr_word}" == -* ]]; then COMPREPLY=( $(compgen -W "${flag_opts} ${arg_opts}" -- "${curr_word}") ) @@ -723,7 +738,8 @@ function _picocli_picocompletion-demo-help_sub2alias_sub2child3alias() { local currIndex currIndex=$(currentPositionalIndex "sub2child3-alias" "${arg_opts}" "${flag_opts}") if (( currIndex >= 0 && currIndex <= 0 )); then - positionals=$( compgen -W "$cands_pos_param_args" -- "${curr_word}" ) + local IFS=$'\n' + positionals=$( compgen -W "${cands_pos_param_args[*]}" -- "${curr_word}" ) elif (( currIndex >= 1 && currIndex <= 2 )); then local IFS=$'\n' type compopt &>/dev/null && compopt -o filenames diff --git a/src/test/resources/picocompletion-demo_completion.bash b/src/test/resources/picocompletion-demo_completion.bash index 996320ca0..95216cbd5 100644 --- a/src/test/resources/picocompletion-demo_completion.bash +++ b/src/test/resources/picocompletion-demo_completion.bash @@ -201,7 +201,7 @@ function _picocli_picocompletion-demo_sub1() { local commands="" local flag_opts="" local arg_opts="--num --str --candidates" - local str2_option_args="aaa bbb ccc" # --candidates values + local str2_option_args=("aaa" "bbb" "ccc") # --candidates values type compopt &>/dev/null && compopt +o default @@ -213,7 +213,8 @@ function _picocli_picocompletion-demo_sub1() { return ;; --candidates) - COMPREPLY=( $( compgen -W "${str2_option_args}" -- "${curr_word}" ) ) + local IFS=$'\n' + COMPREPLY=( $( compgen -W "${str2_option_args[*]}" -- "${curr_word}" ) ) return $? ;; esac @@ -235,7 +236,7 @@ function _picocli_picocompletion-demo_sub1alias() { local commands="" local flag_opts="" local arg_opts="--num --str --candidates" - local str2_option_args="aaa bbb ccc" # --candidates values + local str2_option_args=("aaa" "bbb" "ccc") # --candidates values type compopt &>/dev/null && compopt +o default @@ -247,7 +248,8 @@ function _picocli_picocompletion-demo_sub1alias() { return ;; --candidates) - COMPREPLY=( $( compgen -W "${str2_option_args}" -- "${curr_word}" ) ) + local IFS=$'\n' + COMPREPLY=( $( compgen -W "${str2_option_args[*]}" -- "${curr_word}" ) ) return $? ;; esac @@ -283,7 +285,7 @@ function _picocli_picocompletion-demo_sub2() { return $? ;; esac - local possibilities_pos_param_args="Aaa Bbb Ccc" # 0-0 values + local possibilities_pos_param_args=("Aaa" "Bbb" "Ccc") # 0-0 values if [[ "${curr_word}" == -* ]]; then COMPREPLY=( $(compgen -W "${flag_opts} ${arg_opts}" -- "${curr_word}") ) @@ -292,7 +294,8 @@ function _picocli_picocompletion-demo_sub2() { local currIndex currIndex=$(currentPositionalIndex "sub2" "${arg_opts}" "${flag_opts}") if (( currIndex >= 0 && currIndex <= 0 )); then - positionals=$( compgen -W "$possibilities_pos_param_args" -- "${curr_word}" ) + local IFS=$'\n' + positionals=$( compgen -W "${possibilities_pos_param_args[*]}" -- "${curr_word}" ) fi COMPREPLY=( $(compgen -W "${commands} ${positionals}" -- "${curr_word}") ) fi @@ -321,7 +324,7 @@ function _picocli_picocompletion-demo_sub2alias() { return $? ;; esac - local possibilities_pos_param_args="Aaa Bbb Ccc" # 0-0 values + local possibilities_pos_param_args=("Aaa" "Bbb" "Ccc") # 0-0 values if [[ "${curr_word}" == -* ]]; then COMPREPLY=( $(compgen -W "${flag_opts} ${arg_opts}" -- "${curr_word}") ) @@ -330,7 +333,8 @@ function _picocli_picocompletion-demo_sub2alias() { local currIndex currIndex=$(currentPositionalIndex "sub2-alias" "${arg_opts}" "${flag_opts}") if (( currIndex >= 0 && currIndex <= 0 )); then - positionals=$( compgen -W "$possibilities_pos_param_args" -- "${curr_word}" ) + local IFS=$'\n' + positionals=$( compgen -W "${possibilities_pos_param_args[*]}" -- "${curr_word}" ) fi COMPREPLY=( $(compgen -W "${commands} ${positionals}" -- "${curr_word}") ) fi @@ -401,20 +405,21 @@ function _picocli_picocompletion-demo_sub2_subsub2() { local commands="" local flag_opts="" local arg_opts="-u --timeUnit -t --timeout" - local timeUnit_option_args="%2$s" # --timeUnit values + local timeUnit_option_args=("%2$s") # --timeUnit values type compopt &>/dev/null && compopt +o default case ${prev_word} in -u|--timeUnit) - COMPREPLY=( $( compgen -W "${timeUnit_option_args}" -- "${curr_word}" ) ) + local IFS=$'\n' + COMPREPLY=( $( compgen -W "${timeUnit_option_args[*]}" -- "${curr_word}" ) ) return $? ;; -t|--timeout) return ;; esac - local str2_pos_param_args="aaa bbb ccc" # 0-0 values + local str2_pos_param_args=("aaa" "bbb" "ccc") # 0-0 values if [[ "${curr_word}" == -* ]]; then COMPREPLY=( $(compgen -W "${flag_opts} ${arg_opts}" -- "${curr_word}") ) @@ -423,7 +428,8 @@ function _picocli_picocompletion-demo_sub2_subsub2() { local currIndex currIndex=$(currentPositionalIndex "subsub2" "${arg_opts}" "${flag_opts}") if (( currIndex >= 0 && currIndex <= 0 )); then - positionals=$( compgen -W "$str2_pos_param_args" -- "${curr_word}" ) + local IFS=$'\n' + positionals=$( compgen -W "${str2_pos_param_args[*]}" -- "${curr_word}" ) fi COMPREPLY=( $(compgen -W "${commands} ${positionals}" -- "${curr_word}") ) fi @@ -438,20 +444,21 @@ function _picocli_picocompletion-demo_sub2_sub2child2alias() { local commands="" local flag_opts="" local arg_opts="-u --timeUnit -t --timeout" - local timeUnit_option_args="%2$s" # --timeUnit values + local timeUnit_option_args=("%2$s") # --timeUnit values type compopt &>/dev/null && compopt +o default case ${prev_word} in -u|--timeUnit) - COMPREPLY=( $( compgen -W "${timeUnit_option_args}" -- "${curr_word}" ) ) + local IFS=$'\n' + COMPREPLY=( $( compgen -W "${timeUnit_option_args[*]}" -- "${curr_word}" ) ) return $? ;; -t|--timeout) return ;; esac - local str2_pos_param_args="aaa bbb ccc" # 0-0 values + local str2_pos_param_args=("aaa" "bbb" "ccc") # 0-0 values if [[ "${curr_word}" == -* ]]; then COMPREPLY=( $(compgen -W "${flag_opts} ${arg_opts}" -- "${curr_word}") ) @@ -460,7 +467,8 @@ function _picocli_picocompletion-demo_sub2_sub2child2alias() { local currIndex currIndex=$(currentPositionalIndex "sub2child2-alias" "${arg_opts}" "${flag_opts}") if (( currIndex >= 0 && currIndex <= 0 )); then - positionals=$( compgen -W "$str2_pos_param_args" -- "${curr_word}" ) + local IFS=$'\n' + positionals=$( compgen -W "${str2_pos_param_args[*]}" -- "${curr_word}" ) fi COMPREPLY=( $(compgen -W "${commands} ${positionals}" -- "${curr_word}") ) fi @@ -474,7 +482,7 @@ function _picocli_picocompletion-demo_sub2_subsub3() { local commands="" local flag_opts="" local arg_opts="" - local cands_pos_param_args="aaa bbb ccc" # 0-0 values + local cands_pos_param_args=("aaa" "bbb" "ccc") # 0-0 values if [[ "${curr_word}" == -* ]]; then COMPREPLY=( $(compgen -W "${flag_opts} ${arg_opts}" -- "${curr_word}") ) @@ -483,7 +491,8 @@ function _picocli_picocompletion-demo_sub2_subsub3() { local currIndex currIndex=$(currentPositionalIndex "subsub3" "${arg_opts}" "${flag_opts}") if (( currIndex >= 0 && currIndex <= 0 )); then - positionals=$( compgen -W "$cands_pos_param_args" -- "${curr_word}" ) + local IFS=$'\n' + positionals=$( compgen -W "${cands_pos_param_args[*]}" -- "${curr_word}" ) elif (( currIndex >= 1 && currIndex <= 2 )); then local IFS=$'\n' type compopt &>/dev/null && compopt -o filenames @@ -504,7 +513,7 @@ function _picocli_picocompletion-demo_sub2_sub2child3alias() { local commands="" local flag_opts="" local arg_opts="" - local cands_pos_param_args="aaa bbb ccc" # 0-0 values + local cands_pos_param_args=("aaa" "bbb" "ccc") # 0-0 values if [[ "${curr_word}" == -* ]]; then COMPREPLY=( $(compgen -W "${flag_opts} ${arg_opts}" -- "${curr_word}") ) @@ -513,7 +522,8 @@ function _picocli_picocompletion-demo_sub2_sub2child3alias() { local currIndex currIndex=$(currentPositionalIndex "sub2child3-alias" "${arg_opts}" "${flag_opts}") if (( currIndex >= 0 && currIndex <= 0 )); then - positionals=$( compgen -W "$cands_pos_param_args" -- "${curr_word}" ) + local IFS=$'\n' + positionals=$( compgen -W "${cands_pos_param_args[*]}" -- "${curr_word}" ) elif (( currIndex >= 1 && currIndex <= 2 )); then local IFS=$'\n' type compopt &>/dev/null && compopt -o filenames @@ -591,20 +601,21 @@ function _picocli_picocompletion-demo_sub2alias_subsub2() { local commands="" local flag_opts="" local arg_opts="-u --timeUnit -t --timeout" - local timeUnit_option_args="%2$s" # --timeUnit values + local timeUnit_option_args=("%2$s") # --timeUnit values type compopt &>/dev/null && compopt +o default case ${prev_word} in -u|--timeUnit) - COMPREPLY=( $( compgen -W "${timeUnit_option_args}" -- "${curr_word}" ) ) + local IFS=$'\n' + COMPREPLY=( $( compgen -W "${timeUnit_option_args[*]}" -- "${curr_word}" ) ) return $? ;; -t|--timeout) return ;; esac - local str2_pos_param_args="aaa bbb ccc" # 0-0 values + local str2_pos_param_args=("aaa" "bbb" "ccc") # 0-0 values if [[ "${curr_word}" == -* ]]; then COMPREPLY=( $(compgen -W "${flag_opts} ${arg_opts}" -- "${curr_word}") ) @@ -613,7 +624,8 @@ function _picocli_picocompletion-demo_sub2alias_subsub2() { local currIndex currIndex=$(currentPositionalIndex "subsub2" "${arg_opts}" "${flag_opts}") if (( currIndex >= 0 && currIndex <= 0 )); then - positionals=$( compgen -W "$str2_pos_param_args" -- "${curr_word}" ) + local IFS=$'\n' + positionals=$( compgen -W "${str2_pos_param_args[*]}" -- "${curr_word}" ) fi COMPREPLY=( $(compgen -W "${commands} ${positionals}" -- "${curr_word}") ) fi @@ -628,20 +640,21 @@ function _picocli_picocompletion-demo_sub2alias_sub2child2alias() { local commands="" local flag_opts="" local arg_opts="-u --timeUnit -t --timeout" - local timeUnit_option_args="%2$s" # --timeUnit values + local timeUnit_option_args=("%2$s") # --timeUnit values type compopt &>/dev/null && compopt +o default case ${prev_word} in -u|--timeUnit) - COMPREPLY=( $( compgen -W "${timeUnit_option_args}" -- "${curr_word}" ) ) + local IFS=$'\n' + COMPREPLY=( $( compgen -W "${timeUnit_option_args[*]}" -- "${curr_word}" ) ) return $? ;; -t|--timeout) return ;; esac - local str2_pos_param_args="aaa bbb ccc" # 0-0 values + local str2_pos_param_args=("aaa" "bbb" "ccc") # 0-0 values if [[ "${curr_word}" == -* ]]; then COMPREPLY=( $(compgen -W "${flag_opts} ${arg_opts}" -- "${curr_word}") ) @@ -650,7 +663,8 @@ function _picocli_picocompletion-demo_sub2alias_sub2child2alias() { local currIndex currIndex=$(currentPositionalIndex "sub2child2-alias" "${arg_opts}" "${flag_opts}") if (( currIndex >= 0 && currIndex <= 0 )); then - positionals=$( compgen -W "$str2_pos_param_args" -- "${curr_word}" ) + local IFS=$'\n' + positionals=$( compgen -W "${str2_pos_param_args[*]}" -- "${curr_word}" ) fi COMPREPLY=( $(compgen -W "${commands} ${positionals}" -- "${curr_word}") ) fi @@ -664,7 +678,7 @@ function _picocli_picocompletion-demo_sub2alias_subsub3() { local commands="" local flag_opts="" local arg_opts="" - local cands_pos_param_args="aaa bbb ccc" # 0-0 values + local cands_pos_param_args=("aaa" "bbb" "ccc") # 0-0 values if [[ "${curr_word}" == -* ]]; then COMPREPLY=( $(compgen -W "${flag_opts} ${arg_opts}" -- "${curr_word}") ) @@ -673,7 +687,8 @@ function _picocli_picocompletion-demo_sub2alias_subsub3() { local currIndex currIndex=$(currentPositionalIndex "subsub3" "${arg_opts}" "${flag_opts}") if (( currIndex >= 0 && currIndex <= 0 )); then - positionals=$( compgen -W "$cands_pos_param_args" -- "${curr_word}" ) + local IFS=$'\n' + positionals=$( compgen -W "${cands_pos_param_args[*]}" -- "${curr_word}" ) elif (( currIndex >= 1 && currIndex <= 2 )); then local IFS=$'\n' type compopt &>/dev/null && compopt -o filenames @@ -694,7 +709,7 @@ function _picocli_picocompletion-demo_sub2alias_sub2child3alias() { local commands="" local flag_opts="" local arg_opts="" - local cands_pos_param_args="aaa bbb ccc" # 0-0 values + local cands_pos_param_args=("aaa" "bbb" "ccc") # 0-0 values if [[ "${curr_word}" == -* ]]; then COMPREPLY=( $(compgen -W "${flag_opts} ${arg_opts}" -- "${curr_word}") ) @@ -703,7 +718,8 @@ function _picocli_picocompletion-demo_sub2alias_sub2child3alias() { local currIndex currIndex=$(currentPositionalIndex "sub2child3-alias" "${arg_opts}" "${flag_opts}") if (( currIndex >= 0 && currIndex <= 0 )); then - positionals=$( compgen -W "$cands_pos_param_args" -- "${curr_word}" ) + local IFS=$'\n' + positionals=$( compgen -W "${cands_pos_param_args[*]}" -- "${curr_word}" ) elif (( currIndex >= 1 && currIndex <= 2 )); then local IFS=$'\n' type compopt &>/dev/null && compopt -o filenames