Skip to content

Commit c00e94f

Browse files
al3xtjamesfelinira
authored andcommitted
cli: Correct binary name in shell completions
`wormhole-rs completion` currently produces completions for a binary named `magic-wormhole-cli`, which is not the name listed in Cargo.toml. This causes the completions to not work. Fix the completions by using the name from the [`CARGO_BIN_NAME` environment variable][1]. [1]: https://doc.rust-lang.org/cargo/reference/environment-variables.html#environment-variables-cargo-sets-for-crates
1 parent 7257de1 commit c00e94f

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

cli/src/main.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -505,15 +505,15 @@ async fn main() -> eyre::Result<()> {
505505
},
506506
WormholeCommand::Completion { shell } => {
507507
let mut cmd = WormholeCli::command();
508-
let binary_name = cmd.get_name().to_string();
508+
let binary_name = env!("CARGO_BIN_NAME");
509509

510510
match shell {
511511
shell @ clap_complete::Shell::Zsh => {
512512
// for zsh, we will wrap the output to make it easier to use
513513
// this way we can source it directly `source <(wormhole-rs completion zsh)`
514514

515515
let mut out = Vec::new();
516-
clap_complete::generate(shell, &mut cmd, &binary_name, &mut out);
516+
clap_complete::generate(shell, &mut cmd, binary_name, &mut out);
517517
let out = String::from_utf8(out)
518518
.expect("Internal error: shell completion not UTF-8 encoded");
519519
let out = format!(
@@ -1196,10 +1196,10 @@ mod test {
11961196

11971197
for shell in clap_complete::Shell::value_variants() {
11981198
let mut cmd = WormholeCli::command();
1199-
let binary_name = cmd.get_name().to_string();
1199+
let binary_name = env!("CARGO_BIN_NAME");
12001200

12011201
let mut out = Vec::new();
1202-
clap_complete::generate(*shell, &mut cmd, &binary_name, &mut out);
1202+
clap_complete::generate(*shell, &mut cmd, binary_name, &mut out);
12031203
String::from_utf8(out).unwrap();
12041204
}
12051205
}

0 commit comments

Comments
 (0)