@@ -756,6 +756,41 @@ private String expectedCompletionScriptForAutoCompleteApp() {
756
756
" echo \" $result\" \n " +
757
757
"}\n " +
758
758
"\n " +
759
+ "# compReplyArray generates a list of completion suggestions based on an array, ensuring all values are properly escaped.\n " +
760
+ "#\n " +
761
+ "# compReplyArray takes a single parameter: the array of options to be displayed\n " +
762
+ "#\n " +
763
+ "# The output is echoed to std_out, one option per line.\n " +
764
+ "#\n " +
765
+ "# Example usage:\n " +
766
+ "# local options=(\" foo\" , \" bar\" , \" baz\" )\n " +
767
+ "# local IFS=$'\\ n'\n " +
768
+ "# COMPREPLY=$(compReplyArray \" ${options[@]}\" )\n " +
769
+ "function compReplyArray() {\n " +
770
+ " declare -a options\n " +
771
+ " options=(\" $@\" )\n " +
772
+ " local curr_word=${COMP_WORDS[COMP_CWORD]}\n " +
773
+ " local i\n " +
774
+ " local quoted\n " +
775
+ " local optionList=()\n " +
776
+ "\n " +
777
+ " for (( i=0; i<${#options[@]}; i++ )); do\n " +
778
+ " # Double escape, since we want escaped values, but compgen -W expands the argument\n " +
779
+ " printf -v quoted %%q \" ${options[i]}\" \n " +
780
+ " quoted=\\ '${quoted//\\ '/\\ '\\ \\ \\ '\\ '}\\ '\n " +
781
+ "\n " +
782
+ " optionList[i]=$quoted\n " +
783
+ " done\n " +
784
+ "\n " +
785
+ " # We also have to add another round of escaping to $curr_word.\n " +
786
+ " curr_word=${curr_word//\\ \\ /\\ \\ \\ \\ }\n " +
787
+ " curr_word=${curr_word//\\ '/\\ \\ \\ '}\n " +
788
+ "\n " +
789
+ " # Actually generate completions.\n " +
790
+ " local IFS=$'\\ n'\n " +
791
+ " echo -e \" $(compgen -W \" ${optionList[*]}\" -- \" $curr_word\" )\" \n " +
792
+ "}\n " +
793
+ "\n " +
759
794
"# Bash completion entry point function.\n " +
760
795
"# _complete_picocli.AutoComplete finds which commands and subcommands have been specified\n " +
761
796
"# on the command line and delegates to the appropriate function\n " +
@@ -974,6 +1009,41 @@ private String expectedCompletionScriptForNonDefault() {
974
1009
" echo \" $result\" \n " +
975
1010
"}\n " +
976
1011
"\n " +
1012
+ "# compReplyArray generates a list of completion suggestions based on an array, ensuring all values are properly escaped.\n " +
1013
+ "#\n " +
1014
+ "# compReplyArray takes a single parameter: the array of options to be displayed\n " +
1015
+ "#\n " +
1016
+ "# The output is echoed to std_out, one option per line.\n " +
1017
+ "#\n " +
1018
+ "# Example usage:\n " +
1019
+ "# local options=(\" foo\" , \" bar\" , \" baz\" )\n " +
1020
+ "# local IFS=$'\\ n'\n " +
1021
+ "# COMPREPLY=$(compReplyArray \" ${options[@]}\" )\n " +
1022
+ "function compReplyArray() {\n " +
1023
+ " declare -a options\n " +
1024
+ " options=(\" $@\" )\n " +
1025
+ " local curr_word=${COMP_WORDS[COMP_CWORD]}\n " +
1026
+ " local i\n " +
1027
+ " local quoted\n " +
1028
+ " local optionList=()\n " +
1029
+ "\n " +
1030
+ " for (( i=0; i<${#options[@]}; i++ )); do\n " +
1031
+ " # Double escape, since we want escaped values, but compgen -W expands the argument\n " +
1032
+ " printf -v quoted %%q \" ${options[i]}\" \n " +
1033
+ " quoted=\\ '${quoted//\\ '/\\ '\\ \\ \\ '\\ '}\\ '\n " +
1034
+ "\n " +
1035
+ " optionList[i]=$quoted\n " +
1036
+ " done\n " +
1037
+ "\n " +
1038
+ " # We also have to add another round of escaping to $curr_word.\n " +
1039
+ " curr_word=${curr_word//\\ \\ /\\ \\ \\ \\ }\n " +
1040
+ " curr_word=${curr_word//\\ '/\\ \\ \\ '}\n " +
1041
+ "\n " +
1042
+ " # Actually generate completions.\n " +
1043
+ " local IFS=$'\\ n'\n " +
1044
+ " echo -e \" $(compgen -W \" ${optionList[*]}\" -- \" $curr_word\" )\" \n " +
1045
+ "}\n " +
1046
+ "\n " +
977
1047
"# Bash completion entry point function.\n " +
978
1048
"# _complete_nondefault finds which commands and subcommands have been specified\n " +
979
1049
"# on the command line and delegates to the appropriate function\n " +
@@ -1540,6 +1610,41 @@ private String getCompletionScriptText(String cmdName) {
1540
1610
" echo \" $result\" \n " +
1541
1611
"}\n " +
1542
1612
"\n " +
1613
+ "# compReplyArray generates a list of completion suggestions based on an array, ensuring all values are properly escaped.\n " +
1614
+ "#\n " +
1615
+ "# compReplyArray takes a single parameter: the array of options to be displayed\n " +
1616
+ "#\n " +
1617
+ "# The output is echoed to std_out, one option per line.\n " +
1618
+ "#\n " +
1619
+ "# Example usage:\n " +
1620
+ "# local options=(\" foo\" , \" bar\" , \" baz\" )\n " +
1621
+ "# local IFS=$'\\ n'\n " +
1622
+ "# COMPREPLY=$(compReplyArray \" ${options[@]}\" )\n " +
1623
+ "function compReplyArray() {\n " +
1624
+ " declare -a options\n " +
1625
+ " options=(\" $@\" )\n " +
1626
+ " local curr_word=${COMP_WORDS[COMP_CWORD]}\n " +
1627
+ " local i\n " +
1628
+ " local quoted\n " +
1629
+ " local optionList=()\n " +
1630
+ "\n " +
1631
+ " for (( i=0; i<${#options[@]}; i++ )); do\n " +
1632
+ " # Double escape, since we want escaped values, but compgen -W expands the argument\n " +
1633
+ " printf -v quoted %%q \" ${options[i]}\" \n " +
1634
+ " quoted=\\ '${quoted//\\ '/\\ '\\ \\ \\ '\\ '}\\ '\n " +
1635
+ "\n " +
1636
+ " optionList[i]=$quoted\n " +
1637
+ " done\n " +
1638
+ "\n " +
1639
+ " # We also have to add another round of escaping to $curr_word.\n " +
1640
+ " curr_word=${curr_word//\\ \\ /\\ \\ \\ \\ }\n " +
1641
+ " curr_word=${curr_word//\\ '/\\ \\ \\ '}\n " +
1642
+ "\n " +
1643
+ " # Actually generate completions.\n " +
1644
+ " local IFS=$'\\ n'\n " +
1645
+ " echo -e \" $(compgen -W \" ${optionList[*]}\" -- \" $curr_word\" )\" \n " +
1646
+ "}\n " +
1647
+ "\n " +
1543
1648
"# Bash completion entry point function.\n " +
1544
1649
"# _complete_%1$s finds which commands and subcommands have been specified\n " +
1545
1650
"# on the command line and delegates to the appropriate function\n " +
@@ -1752,6 +1857,41 @@ private String getCompletionScriptTextWithHidden(String commandName) {
1752
1857
" echo \" $result\" \n " +
1753
1858
"}\n " +
1754
1859
"\n " +
1860
+ "# compReplyArray generates a list of completion suggestions based on an array, ensuring all values are properly escaped.\n " +
1861
+ "#\n " +
1862
+ "# compReplyArray takes a single parameter: the array of options to be displayed\n " +
1863
+ "#\n " +
1864
+ "# The output is echoed to std_out, one option per line.\n " +
1865
+ "#\n " +
1866
+ "# Example usage:\n " +
1867
+ "# local options=(\" foo\" , \" bar\" , \" baz\" )\n " +
1868
+ "# local IFS=$'\\ n'\n " +
1869
+ "# COMPREPLY=$(compReplyArray \" ${options[@]}\" )\n " +
1870
+ "function compReplyArray() {\n " +
1871
+ " declare -a options\n " +
1872
+ " options=(\" $@\" )\n " +
1873
+ " local curr_word=${COMP_WORDS[COMP_CWORD]}\n " +
1874
+ " local i\n " +
1875
+ " local quoted\n " +
1876
+ " local optionList=()\n " +
1877
+ "\n " +
1878
+ " for (( i=0; i<${#options[@]}; i++ )); do\n " +
1879
+ " # Double escape, since we want escaped values, but compgen -W expands the argument\n " +
1880
+ " printf -v quoted %%q \" ${options[i]}\" \n " +
1881
+ " quoted=\\ '${quoted//\\ '/\\ '\\ \\ \\ '\\ '}\\ '\n " +
1882
+ "\n " +
1883
+ " optionList[i]=$quoted\n " +
1884
+ " done\n " +
1885
+ "\n " +
1886
+ " # We also have to add another round of escaping to $curr_word.\n " +
1887
+ " curr_word=${curr_word//\\ \\ /\\ \\ \\ \\ }\n " +
1888
+ " curr_word=${curr_word//\\ '/\\ \\ \\ '}\n " +
1889
+ "\n " +
1890
+ " # Actually generate completions.\n " +
1891
+ " local IFS=$'\\ n'\n " +
1892
+ " echo -e \" $(compgen -W \" ${optionList[*]}\" -- \" $curr_word\" )\" \n " +
1893
+ "}\n " +
1894
+ "\n " +
1755
1895
"# Bash completion entry point function.\n " +
1756
1896
"# _complete_%1$s finds which commands and subcommands have been specified\n " +
1757
1897
"# on the command line and delegates to the appropriate function\n " +
0 commit comments