-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(complete): Strip wrappers for running completer
- Loading branch information
Showing
2 changed files
with
18 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -161,7 +161,7 @@ impl<'s, F: FnOnce() -> clap::Command> CompleteEnv<'s, F> { | |
|
||
/// Override the binary to call to get completions | ||
/// | ||
/// Default: `Command::get_bin_name` | ||
/// Default: `args_os()[0]` | ||
pub fn completer(mut self, completer: impl Into<String>) -> Self { | ||
self.completer = Some(completer.into()); | ||
self | ||
|
@@ -242,6 +242,7 @@ impl<'s, F: FnOnce() -> clap::Command> CompleteEnv<'s, F> { | |
let mut cmd = (self.factory)(); | ||
cmd.build(); | ||
|
||
let completer = args.remove(0); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
epage
Author
Member
|
||
let escape_index = args | ||
.iter() | ||
.position(|a| *a == "--") | ||
|
@@ -255,14 +256,20 @@ impl<'s, F: FnOnce() -> clap::Command> CompleteEnv<'s, F> { | |
.as_deref() | ||
.or_else(|| cmd.get_bin_name()) | ||
.unwrap_or_else(|| cmd.get_name()); | ||
let completer = self | ||
.completer | ||
.as_deref() | ||
.or_else(|| cmd.get_bin_name()) | ||
.unwrap_or_else(|| cmd.get_name()); | ||
let completer = if let Some(completer) = self.completer.as_deref() { | ||
completer.to_owned() | ||
} else { | ||
let mut completer = std::path::PathBuf::from(completer); | ||
if let Some(current_dir) = current_dir.as_deref() { | ||
if 1 < completer.components().count() { | ||
completer = current_dir.join(completer); | ||
} | ||
} | ||
completer.to_string_lossy().into_owned() | ||
}; | ||
|
||
let mut buf = Vec::new(); | ||
shell.write_registration(self.var, name, bin, completer, &mut buf)?; | ||
shell.write_registration(self.var, name, bin, &completer, &mut buf)?; | ||
std::io::stdout().write_all(&buf)?; | ||
} else { | ||
let mut buf = Vec::new(); | ||
|
Should this call be conditional in terms of
cmd::no_binary_name()
?I found this while trying to complete a case where there's no binary name in the args.
Let me know if this comment is not helpful and I won't do it again :)