fix(complete)!: Rename CustomCompleter to ValueCandidates

This commit is contained in:
Ed Page 2024-08-20 08:48:19 -05:00
parent 108907385c
commit 71c5e27f8b
3 changed files with 8 additions and 8 deletions

View file

@ -5,7 +5,7 @@ use clap::builder::ArgExt;
use super::CompletionCandidate;
/// Extend [`Arg`][clap::Arg] with a [`CustomCompleter`]
/// Extend [`Arg`][clap::Arg] with a [`ValueCandidates`]
///
/// # Example
///
@ -23,13 +23,13 @@ use super::CompletionCandidate;
/// }
/// ```
#[derive(Clone)]
pub struct ArgValueCompleter(Arc<dyn CustomCompleter>);
pub struct ArgValueCompleter(Arc<dyn ValueCandidates>);
impl ArgValueCompleter {
/// Create a new `ArgValueCompleter` with a custom completer
pub fn new<C>(completer: C) -> Self
where
C: CustomCompleter + 'static,
C: ValueCandidates + 'static,
{
Self(Arc::new(completer))
}
@ -53,14 +53,14 @@ impl ArgExt for ArgValueCompleter {}
/// User-provided completion candidates for an [`Arg`][clap::Arg], see [`ArgValueCompleter`]
///
/// This is useful when predefined value hints are not enough.
pub trait CustomCompleter: Send + Sync {
pub trait ValueCandidates: Send + Sync {
/// All potential candidates for an argument.
///
/// See [`CompletionCandidate`] for more information.
fn candidates(&self) -> Vec<CompletionCandidate>;
}
impl<F> CustomCompleter for F
impl<F> ValueCandidates for F
where
F: Fn() -> Vec<CompletionCandidate> + Send + Sync,
{

View file

@ -9,4 +9,4 @@ mod custom;
pub use candidate::CompletionCandidate;
pub use complete::complete;
pub use custom::ArgValueCompleter;
pub use custom::CustomCompleter;
pub use custom::ValueCandidates;

View file

@ -4,7 +4,7 @@ use std::fs;
use std::path::Path;
use clap::{builder::PossibleValue, Command};
use clap_complete::engine::{ArgValueCompleter, CompletionCandidate, CustomCompleter};
use clap_complete::engine::{ArgValueCompleter, CompletionCandidate, ValueCandidates};
use snapbox::assert_data_eq;
macro_rules! complete {
@ -596,7 +596,7 @@ fn suggest_custom_arg_value() {
#[derive(Debug)]
struct MyCustomCompleter {}
impl CustomCompleter for MyCustomCompleter {
impl ValueCandidates for MyCustomCompleter {
fn candidates(&self) -> Vec<CompletionCandidate> {
vec![
CompletionCandidate::new("custom1"),