Skip to content

Commit acbb822

Browse files
committed
fix(complete): Reduce risk of conflict with actual subcommands
Fixes #6339
1 parent a49fadb commit acbb822

20 files changed

Lines changed: 604 additions & 604 deletions

clap_complete/src/aot/shells/bash.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,4 +307,4 @@ fn all_options_for_path(cmd: &Command, path: &str) -> String {
307307
opts
308308
}
309309

310-
const CMD_SEP: &str = "__";
310+
const CMD_SEP: &str = "__subcmd__";

clap_complete/src/aot/shells/zsh.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -678,7 +678,7 @@ fn write_positionals_of(p: &Command) -> String {
678678
ret.join("\n")
679679
}
680680

681-
const CMD_SEP: &str = "__";
681+
const CMD_SEP: &str = "__subcmd__";
682682

683683
#[cfg(test)]
684684
mod tests {

clap_complete/tests/snapshots/basic.bash

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,16 @@ _my-app() {
1717
cmd="my__app"
1818
;;
1919
my__app,help)
20-
cmd="my__app__help"
20+
cmd="my__app__subcmd__help"
2121
;;
2222
my__app,test)
23-
cmd="my__app__test"
23+
cmd="my__app__subcmd__test"
2424
;;
25-
my__app__help,help)
26-
cmd="my__app__help__help"
25+
my__app__subcmd__help,help)
26+
cmd="my__app__subcmd__help__subcmd__help"
2727
;;
28-
my__app__help,test)
29-
cmd="my__app__help__test"
28+
my__app__subcmd__help,test)
29+
cmd="my__app__subcmd__help__subcmd__test"
3030
;;
3131
*)
3232
;;
@@ -48,7 +48,7 @@ _my-app() {
4848
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
4949
return 0
5050
;;
51-
my__app__help)
51+
my__subcmd__app__subcmd__help)
5252
opts="test help"
5353
if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
5454
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
@@ -62,7 +62,7 @@ _my-app() {
6262
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
6363
return 0
6464
;;
65-
my__app__help__help)
65+
my__subcmd__app__subcmd__help__subcmd__help)
6666
opts=""
6767
if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then
6868
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
@@ -76,7 +76,7 @@ _my-app() {
7676
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
7777
return 0
7878
;;
79-
my__app__help__test)
79+
my__subcmd__app__subcmd__help__subcmd__test)
8080
opts=""
8181
if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then
8282
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
@@ -90,7 +90,7 @@ _my-app() {
9090
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
9191
return 0
9292
;;
93-
my__app__test)
93+
my__subcmd__app__subcmd__test)
9494
opts="-d -c -h --help"
9595
if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
9696
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )

clap_complete/tests/snapshots/basic.zsh

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ _arguments "${_arguments_options[@]}" : \
3838
;;
3939
(help)
4040
_arguments "${_arguments_options[@]}" : \
41-
":: :_my-app__help_commands" \
41+
":: :_my-app__subcmd__help_commands" \
4242
"*::: :->help" \
4343
&& ret=0
4444

@@ -73,26 +73,26 @@ _my-app_commands() {
7373
)
7474
_describe -t commands 'my-app commands' commands "$@"
7575
}
76-
(( $+functions[_my-app__help_commands] )) ||
77-
_my-app__help_commands() {
76+
(( $+functions[_my-app__subcmd__help_commands] )) ||
77+
_my-app__subcmd__help_commands() {
7878
local commands; commands=(
7979
'test:Subcommand with a second line' \
8080
'help:Print this message or the help of the given subcommand(s)' \
8181
)
8282
_describe -t commands 'my-app help commands' commands "$@"
8383
}
84-
(( $+functions[_my-app__help__help_commands] )) ||
85-
_my-app__help__help_commands() {
84+
(( $+functions[_my-app__subcmd__help__subcmd__help_commands] )) ||
85+
_my-app__subcmd__help__subcmd__help_commands() {
8686
local commands; commands=()
8787
_describe -t commands 'my-app help help commands' commands "$@"
8888
}
89-
(( $+functions[_my-app__help__test_commands] )) ||
90-
_my-app__help__test_commands() {
89+
(( $+functions[_my-app__subcmd__help__subcmd__test_commands] )) ||
90+
_my-app__subcmd__help__subcmd__test_commands() {
9191
local commands; commands=()
9292
_describe -t commands 'my-app help test commands' commands "$@"
9393
}
94-
(( $+functions[_my-app__test_commands] )) ||
95-
_my-app__test_commands() {
94+
(( $+functions[_my-app__subcmd__test_commands] )) ||
95+
_my-app__subcmd__test_commands() {
9696
local commands; commands=()
9797
_describe -t commands 'my-app test commands' commands "$@"
9898
}

clap_complete/tests/snapshots/custom_bin_name.bash

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,16 @@ _bin-name() {
1717
cmd="bin__name"
1818
;;
1919
bin__name,help)
20-
cmd="bin__name__help"
20+
cmd="bin__name__subcmd__help"
2121
;;
2222
bin__name,test)
23-
cmd="bin__name__test"
23+
cmd="bin__name__subcmd__test"
2424
;;
25-
bin__name__help,help)
26-
cmd="bin__name__help__help"
25+
bin__name__subcmd__help,help)
26+
cmd="bin__name__subcmd__help__subcmd__help"
2727
;;
28-
bin__name__help,test)
29-
cmd="bin__name__help__test"
28+
bin__name__subcmd__help,test)
29+
cmd="bin__name__subcmd__help__subcmd__test"
3030
;;
3131
*)
3232
;;
@@ -48,7 +48,7 @@ _bin-name() {
4848
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
4949
return 0
5050
;;
51-
bin__name__help)
51+
bin__subcmd__name__subcmd__help)
5252
opts="test help"
5353
if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
5454
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
@@ -62,7 +62,7 @@ _bin-name() {
6262
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
6363
return 0
6464
;;
65-
bin__name__help__help)
65+
bin__subcmd__name__subcmd__help__subcmd__help)
6666
opts=""
6767
if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then
6868
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
@@ -76,7 +76,7 @@ _bin-name() {
7676
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
7777
return 0
7878
;;
79-
bin__name__help__test)
79+
bin__subcmd__name__subcmd__help__subcmd__test)
8080
opts=""
8181
if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then
8282
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
@@ -90,7 +90,7 @@ _bin-name() {
9090
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
9191
return 0
9292
;;
93-
bin__name__test)
93+
bin__subcmd__name__subcmd__test)
9494
opts="-d -c -h --help"
9595
if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
9696
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )

clap_complete/tests/snapshots/custom_bin_name.zsh

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ _arguments "${_arguments_options[@]}" : \
3838
;;
3939
(help)
4040
_arguments "${_arguments_options[@]}" : \
41-
":: :_bin-name__help_commands" \
41+
":: :_bin-name__subcmd__help_commands" \
4242
"*::: :->help" \
4343
&& ret=0
4444

@@ -73,26 +73,26 @@ _bin-name_commands() {
7373
)
7474
_describe -t commands 'bin-name commands' commands "$@"
7575
}
76-
(( $+functions[_bin-name__help_commands] )) ||
77-
_bin-name__help_commands() {
76+
(( $+functions[_bin-name__subcmd__help_commands] )) ||
77+
_bin-name__subcmd__help_commands() {
7878
local commands; commands=(
7979
'test:Subcommand with a second line' \
8080
'help:Print this message or the help of the given subcommand(s)' \
8181
)
8282
_describe -t commands 'bin-name help commands' commands "$@"
8383
}
84-
(( $+functions[_bin-name__help__help_commands] )) ||
85-
_bin-name__help__help_commands() {
84+
(( $+functions[_bin-name__subcmd__help__subcmd__help_commands] )) ||
85+
_bin-name__subcmd__help__subcmd__help_commands() {
8686
local commands; commands=()
8787
_describe -t commands 'bin-name help help commands' commands "$@"
8888
}
89-
(( $+functions[_bin-name__help__test_commands] )) ||
90-
_bin-name__help__test_commands() {
89+
(( $+functions[_bin-name__subcmd__help__subcmd__test_commands] )) ||
90+
_bin-name__subcmd__help__subcmd__test_commands() {
9191
local commands; commands=()
9292
_describe -t commands 'bin-name help test commands' commands "$@"
9393
}
94-
(( $+functions[_bin-name__test_commands] )) ||
95-
_bin-name__test_commands() {
94+
(( $+functions[_bin-name__subcmd__test_commands] )) ||
95+
_bin-name__subcmd__test_commands() {
9696
local commands; commands=()
9797
_describe -t commands 'bin-name test commands' commands "$@"
9898
}

clap_complete/tests/snapshots/external_subcommands.bash

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,16 @@ _my-app() {
1717
cmd="my__app"
1818
;;
1919
my__app,external)
20-
cmd="my__app__external"
20+
cmd="my__app__subcmd__external"
2121
;;
2222
my__app,help)
23-
cmd="my__app__help"
23+
cmd="my__app__subcmd__help"
2424
;;
25-
my__app__help,external)
26-
cmd="my__app__help__external"
25+
my__app__subcmd__help,external)
26+
cmd="my__app__subcmd__help__subcmd__external"
2727
;;
28-
my__app__help,help)
29-
cmd="my__app__help__help"
28+
my__app__subcmd__help,help)
29+
cmd="my__app__subcmd__help__subcmd__help"
3030
;;
3131
*)
3232
;;
@@ -48,7 +48,7 @@ _my-app() {
4848
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
4949
return 0
5050
;;
51-
my__app__external)
51+
my__subcmd__app__subcmd__external)
5252
opts="-h --help"
5353
if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
5454
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
@@ -62,7 +62,7 @@ _my-app() {
6262
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
6363
return 0
6464
;;
65-
my__app__help)
65+
my__subcmd__app__subcmd__help)
6666
opts="external help"
6767
if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
6868
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
@@ -76,7 +76,7 @@ _my-app() {
7676
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
7777
return 0
7878
;;
79-
my__app__help__external)
79+
my__subcmd__app__subcmd__help__subcmd__external)
8080
opts=""
8181
if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then
8282
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
@@ -90,7 +90,7 @@ _my-app() {
9090
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
9191
return 0
9292
;;
93-
my__app__help__help)
93+
my__subcmd__app__subcmd__help__subcmd__help)
9494
opts=""
9595
if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then
9696
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )

clap_complete/tests/snapshots/external_subcommands.zsh

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ _arguments "${_arguments_options[@]}" : \
3535
;;
3636
(help)
3737
_arguments "${_arguments_options[@]}" : \
38-
":: :_my-app__help_commands" \
38+
":: :_my-app__subcmd__help_commands" \
3939
"*::: :->help" \
4040
&& ret=0
4141

@@ -70,26 +70,26 @@ _my-app_commands() {
7070
)
7171
_describe -t commands 'my-app commands' commands "$@"
7272
}
73-
(( $+functions[_my-app__external_commands] )) ||
74-
_my-app__external_commands() {
73+
(( $+functions[_my-app__subcmd__external_commands] )) ||
74+
_my-app__subcmd__external_commands() {
7575
local commands; commands=()
7676
_describe -t commands 'my-app external commands' commands "$@"
7777
}
78-
(( $+functions[_my-app__help_commands] )) ||
79-
_my-app__help_commands() {
78+
(( $+functions[_my-app__subcmd__help_commands] )) ||
79+
_my-app__subcmd__help_commands() {
8080
local commands; commands=(
8181
'external:An external subcommand' \
8282
'help:Print this message or the help of the given subcommand(s)' \
8383
)
8484
_describe -t commands 'my-app help commands' commands "$@"
8585
}
86-
(( $+functions[_my-app__help__external_commands] )) ||
87-
_my-app__help__external_commands() {
86+
(( $+functions[_my-app__subcmd__help__subcmd__external_commands] )) ||
87+
_my-app__subcmd__help__subcmd__external_commands() {
8888
local commands; commands=()
8989
_describe -t commands 'my-app help external commands' commands "$@"
9090
}
91-
(( $+functions[_my-app__help__help_commands] )) ||
92-
_my-app__help__help_commands() {
91+
(( $+functions[_my-app__subcmd__help__subcmd__help_commands] )) ||
92+
_my-app__subcmd__help__subcmd__help_commands() {
9393
local commands; commands=()
9494
_describe -t commands 'my-app help help commands' commands "$@"
9595
}

clap_complete/tests/snapshots/feature_sample.bash

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,16 @@ _my-app() {
1717
cmd="my__app"
1818
;;
1919
my__app,help)
20-
cmd="my__app__help"
20+
cmd="my__app__subcmd__help"
2121
;;
2222
my__app,test)
23-
cmd="my__app__test"
23+
cmd="my__app__subcmd__test"
2424
;;
25-
my__app__help,help)
26-
cmd="my__app__help__help"
25+
my__app__subcmd__help,help)
26+
cmd="my__app__subcmd__help__subcmd__help"
2727
;;
28-
my__app__help,test)
29-
cmd="my__app__help__test"
28+
my__app__subcmd__help,test)
29+
cmd="my__app__subcmd__help__subcmd__test"
3030
;;
3131
*)
3232
;;
@@ -48,7 +48,7 @@ _my-app() {
4848
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
4949
return 0
5050
;;
51-
my__app__help)
51+
my__subcmd__app__subcmd__help)
5252
opts="test help"
5353
if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
5454
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
@@ -62,7 +62,7 @@ _my-app() {
6262
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
6363
return 0
6464
;;
65-
my__app__help__help)
65+
my__subcmd__app__subcmd__help__subcmd__help)
6666
opts=""
6767
if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then
6868
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
@@ -76,7 +76,7 @@ _my-app() {
7676
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
7777
return 0
7878
;;
79-
my__app__help__test)
79+
my__subcmd__app__subcmd__help__subcmd__test)
8080
opts=""
8181
if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then
8282
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
@@ -90,7 +90,7 @@ _my-app() {
9090
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
9191
return 0
9292
;;
93-
my__app__test)
93+
my__subcmd__app__subcmd__test)
9494
opts="-h -V --case --help --version"
9595
if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
9696
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )

0 commit comments

Comments
 (0)