mirror of
https://github.com/clap-rs/clap
synced 2024-12-15 07:12:32 +00:00
fix(complete)!: Rename CustomCompleter::completions to candidates
After thinking on this, I feel like it gives a better sense that the user doesn't get a say in the completion but they give us the options and we take care of it.
This commit is contained in:
parent
7d14ce34de
commit
261116d4b4
3 changed files with 8 additions and 6 deletions
|
@ -408,7 +408,7 @@ fn complete_custom_arg_value(
|
|||
debug!("complete_custom_arg_value: completer={completer:?}, value={value:?}");
|
||||
|
||||
let mut values = Vec::new();
|
||||
let custom_arg_values = completer.completions();
|
||||
let custom_arg_values = completer.candidates();
|
||||
values.extend(custom_arg_values);
|
||||
|
||||
values.retain(|comp| comp.get_content().starts_with(&value.to_string_lossy()));
|
||||
|
|
|
@ -34,9 +34,11 @@ impl ArgValueCompleter {
|
|||
Self(Arc::new(completer))
|
||||
}
|
||||
|
||||
/// All potential candidates for an argument.
|
||||
///
|
||||
/// See [`CompletionCandidate`] for more information.
|
||||
pub fn completions(&self) -> Vec<CompletionCandidate> {
|
||||
self.0.completions()
|
||||
pub fn candidates(&self) -> Vec<CompletionCandidate> {
|
||||
self.0.candidates()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -55,14 +57,14 @@ pub trait CustomCompleter: Send + Sync {
|
|||
/// All potential candidates for an argument.
|
||||
///
|
||||
/// See [`CompletionCandidate`] for more information.
|
||||
fn completions(&self) -> Vec<CompletionCandidate>;
|
||||
fn candidates(&self) -> Vec<CompletionCandidate>;
|
||||
}
|
||||
|
||||
impl<F> CustomCompleter for F
|
||||
where
|
||||
F: Fn() -> Vec<CompletionCandidate> + Send + Sync,
|
||||
{
|
||||
fn completions(&self) -> Vec<CompletionCandidate> {
|
||||
fn candidates(&self) -> Vec<CompletionCandidate> {
|
||||
self()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -597,7 +597,7 @@ fn suggest_custom_arg_value() {
|
|||
struct MyCustomCompleter {}
|
||||
|
||||
impl CustomCompleter for MyCustomCompleter {
|
||||
fn completions(&self) -> Vec<CompletionCandidate> {
|
||||
fn candidates(&self) -> Vec<CompletionCandidate> {
|
||||
vec![
|
||||
CompletionCandidate::new("custom1"),
|
||||
CompletionCandidate::new("custom2"),
|
||||
|
|
Loading…
Reference in a new issue