pub struct CompleteEnv<'s, F> { /* private fields */ }Available on crate feature
unstable-dynamic only.Expand description
Environment-activated completions for your CLI
Benefits over a CLI completion argument or subcommand
- Performance: we don’t need to generate
clap::Commandtwice or parse arguments - Flexibility: there is no concern over it interfering with other CLI logic
Warning: stdout should not be written to before CompleteEnv::complete has had a
chance to run.
§Examples
fn cli() -> clap::Command {
// ...
}
CompleteEnv::with_factory(cli)
.complete()
// ... rest of application logicImplementations§
Source§impl<'s, F: Fn() -> Command> CompleteEnv<'s, F>
impl<'s, F: Fn() -> Command> CompleteEnv<'s, F>
Sourcepub fn with_factory(factory: F) -> Self
pub fn with_factory(factory: F) -> Self
Complete a clap::Command
§Example
Builder:
fn cli() -> clap::Command {
// ...
}
CompleteEnv::with_factory(cli)
.complete()
// ... rest of application logicDerive:
use clap::CommandFactory as _;
#[derive(Debug, Parser)]
struct Cli {
custom: Option<String>,
}
CompleteEnv::with_factory(Cli::command)
.complete()
// ... rest of application logicSourcepub fn var(self, var: &'static str) -> Self
pub fn var(self, var: &'static str) -> Self
Override the environment variable used for enabling completions
Sourcepub fn bin(self, bin: impl Into<String>) -> Self
pub fn bin(self, bin: impl Into<String>) -> Self
Override the name of the binary to complete
Default: Command::get_bin_name
Source§impl<'s, F: Fn() -> Command> CompleteEnv<'s, F>
impl<'s, F: Fn() -> Command> CompleteEnv<'s, F>
Sourcepub fn complete(self)
pub fn complete(self)
Process the completion request and exit
Warning: stdout should not be written to before this has had a
chance to run.
Sourcepub fn try_complete(
self,
args: impl IntoIterator<Item = impl Into<OsString>>,
current_dir: Option<&Path>,
) -> Result<bool>
pub fn try_complete( self, args: impl IntoIterator<Item = impl Into<OsString>>, current_dir: Option<&Path>, ) -> Result<bool>
Process the completion request
Warning: stdout should not be written to before or after this has run.
Returns true if a command was completed and false if this is a regular run of your
application
Auto Trait Implementations§
impl<'s, F> Freeze for CompleteEnv<'s, F>where
F: Freeze,
impl<'s, F> !RefUnwindSafe for CompleteEnv<'s, F>
impl<'s, F> !Send for CompleteEnv<'s, F>
impl<'s, F> !Sync for CompleteEnv<'s, F>
impl<'s, F> Unpin for CompleteEnv<'s, F>where
F: Unpin,
impl<'s, F> UnsafeUnpin for CompleteEnv<'s, F>where
F: UnsafeUnpin,
impl<'s, F> !UnwindSafe for CompleteEnv<'s, F>
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