mirror of
https://github.com/clap-rs/clap
synced 2024-12-13 14:22:34 +00:00
fix(complete)!: Rename ArgValueCompleter to ArgValueCandidates
This commit is contained in:
parent
71c5e27f8b
commit
6ddd5d4e11
7 changed files with 18 additions and 18 deletions
|
@ -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.
|
||||
|
@ -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.
|
||||
|
|
|
@ -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
|
||||
|
@ -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 {
|
||||
|
@ -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:?}");
|
||||
|
||||
|
|
|
@ -11,11 +11,11 @@ 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")] }))]
|
||||
|
@ -23,10 +23,10 @@ use super::CompletionCandidate;
|
|||
/// }
|
||||
/// ```
|
||||
#[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,
|
||||
|
@ -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 {
|
||||
|
|
|
@ -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
clap_complete/src/env/mod.rs
vendored
2
clap_complete/src/env/mod.rs
vendored
|
@ -19,7 +19,7 @@
|
|||
//! To customize completions, see
|
||||
//! - [`ValueHint`][crate::ValueHint]
|
||||
//! - [`ValueEnum`][clap::ValueEnum]
|
||||
//! - [`ArgValueCompleter`][crate::ArgValueCompleter]
|
||||
//! - [`ArgValueCandidates`][crate::ArgValueCandidates]
|
||||
//!
|
||||
//! To source your completions:
|
||||
//!
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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 {
|
||||
|
@ -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!(
|
||||
|
|
Loading…
Reference in a new issue