Skip to content

Commit

Permalink
fix(complete)!: Rename ArgValueCompleter to ArgValueCandidates
Browse files Browse the repository at this point in the history
  • Loading branch information
epage committed Aug 20, 2024
1 parent 71c5e27 commit 6ddd5d4
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 18 deletions.
4 changes: 2 additions & 2 deletions clap_complete/src/command/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ pub use shells::*;
/// To customize completions, see
/// - [`ValueHint`][crate::ValueHint]
/// - [`ValueEnum`][clap::ValueEnum]
/// - [`ArgValueCompleter`][crate::ArgValueCompleter]
/// - [`ArgValueCandidates`][crate::ArgValueCandidates]
///
/// **Warning:** `stdout` should not be written to before [`CompleteCommand::complete`] has had a
/// chance to run.
Expand Down Expand Up @@ -121,7 +121,7 @@ impl CompleteCommand {
/// To customize completions, see
/// - [`ValueHint`][crate::ValueHint]
/// - [`ValueEnum`][clap::ValueEnum]
/// - [`ArgValueCompleter`][crate::ArgValueCompleter]
/// - [`ArgValueCandidates`][crate::ArgValueCandidates]
///
/// **Warning:** `stdout` should not be written to before [`CompleteArgs::complete`] has had a
/// chance to run.
Expand Down
6 changes: 3 additions & 3 deletions clap_complete/src/engine/complete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::ffi::OsString;

use clap_lex::OsStrExt as _;

use super::ArgValueCompleter;
use super::ArgValueCandidates;
use super::CompletionCandidate;

/// Complete the given command, shell-agnostic
Expand Down Expand Up @@ -270,7 +270,7 @@ fn complete_arg_value(
Err(value_os) => value_os,
};

if let Some(completer) = arg.get::<ArgValueCompleter>() {
if let Some(completer) = arg.get::<ArgValueCandidates>() {
values.extend(complete_custom_arg_value(value_os, completer));
} else if let Some(possible_values) = possible_values(arg) {
if let Ok(value) = value {
Expand Down Expand Up @@ -394,7 +394,7 @@ fn complete_path(

fn complete_custom_arg_value(
value: &OsStr,
completer: &ArgValueCompleter,
completer: &ArgValueCandidates,
) -> Vec<CompletionCandidate> {
debug!("complete_custom_arg_value: completer={completer:?}, value={value:?}");

Expand Down
16 changes: 8 additions & 8 deletions clap_complete/src/engine/custom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,22 @@ use super::CompletionCandidate;
///
/// ```rust
/// use clap::Parser;
/// use clap_complete::engine::{ArgValueCompleter, CompletionCandidate};
/// use clap_complete::engine::{ArgValueCandidates, CompletionCandidate};
///
/// #[derive(Debug, Parser)]
/// struct Cli {
/// #[arg(long, add = ArgValueCompleter::new(|| { vec![
/// #[arg(long, add = ArgValueCandidates::new(|| { vec![
/// CompletionCandidate::new("foo"),
/// CompletionCandidate::new("bar"),
/// CompletionCandidate::new("baz")] }))]
/// custom: Option<String>,
/// }
/// ```
#[derive(Clone)]
pub struct ArgValueCompleter(Arc<dyn ValueCandidates>);
pub struct ArgValueCandidates(Arc<dyn ValueCandidates>);

impl ArgValueCompleter {
/// Create a new `ArgValueCompleter` with a custom completer
impl ArgValueCandidates {
/// Create a new `ArgValueCandidates` with a custom completer
pub fn new<C>(completer: C) -> Self
where
C: ValueCandidates + 'static,
Expand All @@ -42,15 +42,15 @@ impl ArgValueCompleter {
}
}

impl std::fmt::Debug for ArgValueCompleter {
impl std::fmt::Debug for ArgValueCandidates {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(type_name::<Self>())
}
}

impl ArgExt for ArgValueCompleter {}
impl ArgExt for ArgValueCandidates {}

/// User-provided completion candidates for an [`Arg`][clap::Arg], see [`ArgValueCompleter`]
/// User-provided completion candidates for an [`Arg`][clap::Arg], see [`ArgValueCandidates`]
///
/// This is useful when predefined value hints are not enough.
pub trait ValueCandidates: Send + Sync {
Expand Down
2 changes: 1 addition & 1 deletion clap_complete/src/engine/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ mod custom;

pub use candidate::CompletionCandidate;
pub use complete::complete;
pub use custom::ArgValueCompleter;
pub use custom::ArgValueCandidates;
pub use custom::ValueCandidates;
2 changes: 1 addition & 1 deletion clap_complete/src/env/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
//! To customize completions, see
//! - [`ValueHint`][crate::ValueHint]
//! - [`ValueEnum`][clap::ValueEnum]
//! - [`ArgValueCompleter`][crate::ArgValueCompleter]
//! - [`ArgValueCandidates`][crate::ArgValueCandidates]
//!
//! To source your completions:
//!
Expand Down
2 changes: 1 addition & 1 deletion clap_complete/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ pub use command::CompleteArgs;
pub use command::CompleteCommand;
#[doc(inline)]
#[cfg(feature = "unstable-dynamic")]
pub use engine::ArgValueCompleter;
pub use engine::ArgValueCandidates;
#[doc(inline)]
#[cfg(feature = "unstable-dynamic")]
pub use engine::CompletionCandidate;
Expand Down
4 changes: 2 additions & 2 deletions clap_complete/tests/testsuite/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::fs;
use std::path::Path;

use clap::{builder::PossibleValue, Command};
use clap_complete::engine::{ArgValueCompleter, CompletionCandidate, ValueCandidates};
use clap_complete::engine::{ArgValueCandidates, CompletionCandidate, ValueCandidates};
use snapbox::assert_data_eq;

macro_rules! complete {
Expand Down Expand Up @@ -609,7 +609,7 @@ fn suggest_custom_arg_value() {
let mut cmd = Command::new("dynamic").arg(
clap::Arg::new("custom")
.long("custom")
.add::<ArgValueCompleter>(ArgValueCompleter::new(MyCustomCompleter {})),
.add::<ArgValueCandidates>(ArgValueCandidates::new(MyCustomCompleter {})),
);

assert_data_eq!(
Expand Down

0 comments on commit 6ddd5d4

Please sign in to comment.