pub struct ArgValueCompleter(/* private fields */);
Available on crate feature
unstable-dynamic
only.Expand description
Extend Arg
with a completer
§Example
use clap::Parser;
use clap_complete::engine::{ArgValueCompleter, CompletionCandidate};
fn custom_completer(current: &std::ffi::OsStr) -> Vec<CompletionCandidate> {
let mut completions = vec![];
let Some(current) = current.to_str() else {
return completions;
};
if "foo".starts_with(current) {
completions.push(CompletionCandidate::new("foo"));
}
if "bar".starts_with(current) {
completions.push(CompletionCandidate::new("bar"));
}
if "baz".starts_with(current) {
completions.push(CompletionCandidate::new("baz"));
}
completions
}
#[derive(Debug, Parser)]
struct Cli {
#[arg(long, add = ArgValueCompleter::new(custom_completer))]
custom: Option<String>,
}
Implementations§
Source§impl ArgValueCompleter
impl ArgValueCompleter
Sourcepub fn new<C>(completer: C) -> Selfwhere
C: ValueCompleter + 'static,
pub fn new<C>(completer: C) -> Selfwhere
C: ValueCompleter + 'static,
Create a new ArgValueCompleter
with a custom completer
Sourcepub fn complete(&self, current: &OsStr) -> Vec<CompletionCandidate>
pub fn complete(&self, current: &OsStr) -> Vec<CompletionCandidate>
Candidates that match current
See CompletionCandidate
for more information.
Trait Implementations§
Source§impl Clone for ArgValueCompleter
impl Clone for ArgValueCompleter
Source§fn clone(&self) -> ArgValueCompleter
fn clone(&self) -> ArgValueCompleter
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreSource§impl Debug for ArgValueCompleter
impl Debug for ArgValueCompleter
impl ArgExt for ArgValueCompleter
Auto Trait Implementations§
impl Freeze for ArgValueCompleter
impl !RefUnwindSafe for ArgValueCompleter
impl Send for ArgValueCompleter
impl Sync for ArgValueCompleter
impl Unpin for ArgValueCompleter
impl !UnwindSafe for ArgValueCompleter
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more