Skip to content

Commit abba196

Browse files
authored
Merge pull request #5688 from epage/rename
fix(complete)!: Rename Custom completer
2 parents 1089073 + 6ddd5d4 commit abba196

File tree

7 files changed

+24
-24
lines changed

7 files changed

+24
-24
lines changed

clap_complete/src/command/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ pub use shells::*;
4949
/// To customize completions, see
5050
/// - [`ValueHint`][crate::ValueHint]
5151
/// - [`ValueEnum`][clap::ValueEnum]
52-
/// - [`ArgValueCompleter`][crate::ArgValueCompleter]
52+
/// - [`ArgValueCandidates`][crate::ArgValueCandidates]
5353
///
5454
/// **Warning:** `stdout` should not be written to before [`CompleteCommand::complete`] has had a
5555
/// chance to run.
@@ -121,7 +121,7 @@ impl CompleteCommand {
121121
/// To customize completions, see
122122
/// - [`ValueHint`][crate::ValueHint]
123123
/// - [`ValueEnum`][clap::ValueEnum]
124-
/// - [`ArgValueCompleter`][crate::ArgValueCompleter]
124+
/// - [`ArgValueCandidates`][crate::ArgValueCandidates]
125125
///
126126
/// **Warning:** `stdout` should not be written to before [`CompleteArgs::complete`] has had a
127127
/// chance to run.

clap_complete/src/engine/complete.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::ffi::OsString;
33

44
use clap_lex::OsStrExt as _;
55

6-
use super::ArgValueCompleter;
6+
use super::ArgValueCandidates;
77
use super::CompletionCandidate;
88

99
/// Complete the given command, shell-agnostic
@@ -270,7 +270,7 @@ fn complete_arg_value(
270270
Err(value_os) => value_os,
271271
};
272272

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

395395
fn complete_custom_arg_value(
396396
value: &OsStr,
397-
completer: &ArgValueCompleter,
397+
completer: &ArgValueCandidates,
398398
) -> Vec<CompletionCandidate> {
399399
debug!("complete_custom_arg_value: completer={completer:?}, value={value:?}");
400400

clap_complete/src/engine/custom.rs

+12-12
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,31 @@ use clap::builder::ArgExt;
55

66
use super::CompletionCandidate;
77

8-
/// Extend [`Arg`][clap::Arg] with a [`CustomCompleter`]
8+
/// Extend [`Arg`][clap::Arg] with a [`ValueCandidates`]
99
///
1010
/// # Example
1111
///
1212
/// ```rust
1313
/// use clap::Parser;
14-
/// use clap_complete::engine::{ArgValueCompleter, CompletionCandidate};
14+
/// use clap_complete::engine::{ArgValueCandidates, CompletionCandidate};
1515
///
1616
/// #[derive(Debug, Parser)]
1717
/// struct Cli {
18-
/// #[arg(long, add = ArgValueCompleter::new(|| { vec![
18+
/// #[arg(long, add = ArgValueCandidates::new(|| { vec![
1919
/// CompletionCandidate::new("foo"),
2020
/// CompletionCandidate::new("bar"),
2121
/// CompletionCandidate::new("baz")] }))]
2222
/// custom: Option<String>,
2323
/// }
2424
/// ```
2525
#[derive(Clone)]
26-
pub struct ArgValueCompleter(Arc<dyn CustomCompleter>);
26+
pub struct ArgValueCandidates(Arc<dyn ValueCandidates>);
2727

28-
impl ArgValueCompleter {
29-
/// Create a new `ArgValueCompleter` with a custom completer
28+
impl ArgValueCandidates {
29+
/// Create a new `ArgValueCandidates` with a custom completer
3030
pub fn new<C>(completer: C) -> Self
3131
where
32-
C: CustomCompleter + 'static,
32+
C: ValueCandidates + 'static,
3333
{
3434
Self(Arc::new(completer))
3535
}
@@ -42,25 +42,25 @@ impl ArgValueCompleter {
4242
}
4343
}
4444

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

51-
impl ArgExt for ArgValueCompleter {}
51+
impl ArgExt for ArgValueCandidates {}
5252

53-
/// User-provided completion candidates for an [`Arg`][clap::Arg], see [`ArgValueCompleter`]
53+
/// User-provided completion candidates for an [`Arg`][clap::Arg], see [`ArgValueCandidates`]
5454
///
5555
/// This is useful when predefined value hints are not enough.
56-
pub trait CustomCompleter: Send + Sync {
56+
pub trait ValueCandidates: Send + Sync {
5757
/// All potential candidates for an argument.
5858
///
5959
/// See [`CompletionCandidate`] for more information.
6060
fn candidates(&self) -> Vec<CompletionCandidate>;
6161
}
6262

63-
impl<F> CustomCompleter for F
63+
impl<F> ValueCandidates for F
6464
where
6565
F: Fn() -> Vec<CompletionCandidate> + Send + Sync,
6666
{

clap_complete/src/engine/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ mod custom;
88

99
pub use candidate::CompletionCandidate;
1010
pub use complete::complete;
11-
pub use custom::ArgValueCompleter;
12-
pub use custom::CustomCompleter;
11+
pub use custom::ArgValueCandidates;
12+
pub use custom::ValueCandidates;

clap_complete/src/env/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
//! To customize completions, see
2020
//! - [`ValueHint`][crate::ValueHint]
2121
//! - [`ValueEnum`][clap::ValueEnum]
22-
//! - [`ArgValueCompleter`][crate::ArgValueCompleter]
22+
//! - [`ArgValueCandidates`][crate::ArgValueCandidates]
2323
//!
2424
//! To source your completions:
2525
//!

clap_complete/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ pub use command::CompleteArgs;
8080
pub use command::CompleteCommand;
8181
#[doc(inline)]
8282
#[cfg(feature = "unstable-dynamic")]
83-
pub use engine::ArgValueCompleter;
83+
pub use engine::ArgValueCandidates;
8484
#[doc(inline)]
8585
#[cfg(feature = "unstable-dynamic")]
8686
pub use engine::CompletionCandidate;

clap_complete/tests/testsuite/engine.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::fs;
44
use std::path::Path;
55

66
use clap::{builder::PossibleValue, Command};
7-
use clap_complete::engine::{ArgValueCompleter, CompletionCandidate, CustomCompleter};
7+
use clap_complete::engine::{ArgValueCandidates, CompletionCandidate, ValueCandidates};
88
use snapbox::assert_data_eq;
99

1010
macro_rules! complete {
@@ -596,7 +596,7 @@ fn suggest_custom_arg_value() {
596596
#[derive(Debug)]
597597
struct MyCustomCompleter {}
598598

599-
impl CustomCompleter for MyCustomCompleter {
599+
impl ValueCandidates for MyCustomCompleter {
600600
fn candidates(&self) -> Vec<CompletionCandidate> {
601601
vec![
602602
CompletionCandidate::new("custom1"),
@@ -609,7 +609,7 @@ fn suggest_custom_arg_value() {
609609
let mut cmd = Command::new("dynamic").arg(
610610
clap::Arg::new("custom")
611611
.long("custom")
612-
.add::<ArgValueCompleter>(ArgValueCompleter::new(MyCustomCompleter {})),
612+
.add::<ArgValueCandidates>(ArgValueCandidates::new(MyCustomCompleter {})),
613613
);
614614

615615
assert_data_eq!(

0 commit comments

Comments
 (0)