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

View file

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