Skip to content

Commit

Permalink
fix(clap_complete): Fix bash completions for when bin_name is set
Browse files Browse the repository at this point in the history
Completions for subcommands in bash where broken when `bin_name`
differed from package-name. Use bin name instead of package name.
  • Loading branch information
Serock3 committed Dec 14, 2023
1 parent d092896 commit 07b02a8
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions clap_complete/src/shells/bash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,15 @@ complete -F _{name} -o nosort -o bashdefault -o default {name}
cmd = bin_name.replace('-', "__"),
name_opts = all_options_for_path(cmd, bin_name),
name_opts_details = option_details_for_path(cmd, bin_name),
subcmds = all_subcommands(cmd),
subcmds = all_subcommands(cmd, bin_name),
subcmd_details = subcommand_details(cmd)
)
.as_bytes()
);
}
}

fn all_subcommands(cmd: &Command) -> String {
fn all_subcommands(cmd: &Command, bin_name: &str) -> String {
debug!("all_subcommands");

fn add_command(
Expand Down Expand Up @@ -102,7 +102,7 @@ fn all_subcommands(cmd: &Command) -> String {
}
}
let mut subcmds = vec![];
let fn_name = cmd.get_name().replace('-', "__");
let fn_name = bin_name.replace('-', "__");
for subcmd in cmd.get_subcommands() {
add_command(&fn_name, subcmd, &mut subcmds);
}
Expand Down

0 comments on commit 07b02a8

Please sign in to comment.