mirror of
https://github.com/clap-rs/clap
synced 2025-01-22 01:14:59 +00:00
fix(complete): Use bin_name
for subcommands
Bash completions for subcommands used package name, which broke completions when the `bin_name` was different. Update the `custom_bin_name` test to reflect the correct behavior.
This commit is contained in:
parent
6411995641
commit
ba378e635c
2 changed files with 14 additions and 13 deletions
|
@ -18,6 +18,8 @@ impl Generator for Bash {
|
||||||
.get_bin_name()
|
.get_bin_name()
|
||||||
.expect("crate::generate should have set the bin_name");
|
.expect("crate::generate should have set the bin_name");
|
||||||
|
|
||||||
|
let fn_name = bin_name.replace('-', "__");
|
||||||
|
|
||||||
w!(
|
w!(
|
||||||
buf,
|
buf,
|
||||||
format!(
|
format!(
|
||||||
|
@ -65,10 +67,10 @@ else
|
||||||
fi
|
fi
|
||||||
",
|
",
|
||||||
name = bin_name,
|
name = bin_name,
|
||||||
cmd = bin_name.replace('-', "__"),
|
cmd = fn_name,
|
||||||
name_opts = all_options_for_path(cmd, bin_name),
|
name_opts = all_options_for_path(cmd, bin_name),
|
||||||
name_opts_details = option_details_for_path(cmd, bin_name),
|
name_opts_details = option_details_for_path(cmd, bin_name),
|
||||||
subcmds = all_subcommands(cmd),
|
subcmds = all_subcommands(cmd, &fn_name),
|
||||||
subcmd_details = subcommand_details(cmd)
|
subcmd_details = subcommand_details(cmd)
|
||||||
)
|
)
|
||||||
.as_bytes()
|
.as_bytes()
|
||||||
|
@ -76,7 +78,7 @@ fi
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn all_subcommands(cmd: &Command) -> String {
|
fn all_subcommands(cmd: &Command, parent_fn_name: &str) -> String {
|
||||||
debug!("all_subcommands");
|
debug!("all_subcommands");
|
||||||
|
|
||||||
fn add_command(
|
fn add_command(
|
||||||
|
@ -106,9 +108,8 @@ fn all_subcommands(cmd: &Command) -> String {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let mut subcmds = vec![];
|
let mut subcmds = vec![];
|
||||||
let fn_name = cmd.get_name().replace('-', "__");
|
|
||||||
for subcmd in cmd.get_subcommands() {
|
for subcmd in cmd.get_subcommands() {
|
||||||
add_command(&fn_name, subcmd, &mut subcmds);
|
add_command(parent_fn_name, subcmd, &mut subcmds);
|
||||||
}
|
}
|
||||||
subcmds.sort();
|
subcmds.sort();
|
||||||
|
|
||||||
|
|
|
@ -12,17 +12,17 @@ _bin-name() {
|
||||||
",$1")
|
",$1")
|
||||||
cmd="bin__name"
|
cmd="bin__name"
|
||||||
;;
|
;;
|
||||||
my__app,help)
|
bin__name,help)
|
||||||
cmd="my__app__help"
|
cmd="bin__name__help"
|
||||||
;;
|
;;
|
||||||
my__app,test)
|
bin__name,test)
|
||||||
cmd="my__app__test"
|
cmd="bin__name__test"
|
||||||
;;
|
;;
|
||||||
my__app__help,help)
|
bin__name__help,help)
|
||||||
cmd="my__app__help__help"
|
cmd="bin__name__help__help"
|
||||||
;;
|
;;
|
||||||
my__app__help,test)
|
bin__name__help,test)
|
||||||
cmd="my__app__help__test"
|
cmd="bin__name__help__test"
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
;;
|
;;
|
||||||
|
|
Loading…
Reference in a new issue