Skip to content

Commit e2aa2f0

Browse files
committed
Feat: Add catch-all on external subcommands for zsh
1 parent b9c0aee commit e2aa2f0

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

clap_complete/src/aot/shells/zsh.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,11 @@ fn get_args_of(parent: &Command, p_global: Option<&Command>) -> String {
353353

354354
let subcommand_text = format!("\"*::: :->{name}\" \\", name = parent.get_name());
355355
segments.push(subcommand_text);
356-
};
356+
} else if parent.is_allow_external_subcommands_set() {
357+
// If the command has an external subcommand value parser, we need to
358+
// add a catch-all for the subcommand. Otherwise there would be no autocompletion whatsoever.
359+
segments.push(String::from("\"*::external_command:_default\" \\"));
360+
}
357361

358362
segments.push(String::from("&& ret=0"));
359363
segments.join("\n")

clap_complete/tests/snapshots/external_subcommands.zsh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ _my-app() {
3030
_arguments "${_arguments_options[@]}" : \
3131
'-h[Print help]' \
3232
'--help[Print help]' \
33+
"*::external_command:_default" \
3334
&& ret=0
3435
;;
3536
(help)

0 commit comments

Comments
 (0)