Skip to main content

Cli

Struct Cli 

Source
pub struct Cli { /* private fields */ }
Expand description

Configured CLI application.

A Cli owns the clap command tree, middleware, registered runtime commands, guides, schemas, and built-ins. Consumer binaries normally create one Cli and call Cli::execute.

Implementations§

Source§

impl Cli

Source

pub fn new(config: CliConfig) -> Self

Builds a CLI application from declarative configuration.

Source

pub fn middleware(&self) -> &Middleware

Returns the shared middleware template.

Source

pub fn middleware_mut(&mut self) -> &mut Middleware

Returns mutable middleware for advanced application setup.

Source

pub async fn execute(&self) -> ExitCode

Executes the CLI with process arguments and process stdout/stderr.

Source

pub async fn execute_from<I, S, O, E>( &self, args: I, stdout: &mut O, stderr: &mut E, ) -> Result<ExitCode>
where I: IntoIterator<Item = S>, S: Into<OsString> + Clone, O: Write, E: Write,

Executes the CLI with caller-provided args and output writers.

Source

pub async fn execute_from_until_signal<I, S, O, E, Shutdown>( &self, args: I, stdout: &mut O, stderr: &mut E, shutdown: Shutdown, ) -> Result<ExitCode>
where I: IntoIterator<Item = S>, S: Into<OsString> + Clone, O: Write, E: Write, Shutdown: Future<Output = ()>,

Executes the CLI until either command completion or a shutdown signal future resolves.

Source

pub fn register_auth_provider( &mut self, provider: Arc<dyn AuthProvider>, ) -> &mut Self

Registers an auth provider after construction.

Source

pub fn root_command(&self) -> &Command

Returns the built clap root command.

Source

pub fn add_module_group( &mut self, category: impl Into<String>, group: RuntimeGroupSpec, ) -> &mut Self

Adds one runtime module group after construction.

Source

pub fn add_module(&mut self, module: Module) -> &mut Self

Adds one module after construction.

Source

pub fn add_command(&mut self, command: RuntimeCommandSpec) -> &mut Self

Adds one top-level runtime command after construction.

Source

pub fn set_has_guide(&mut self, has_guide: bool) -> &mut Self

Controls whether the built-in guide command is advertised.

Source

pub fn add_guides( &mut self, entries: impl IntoIterator<Item = GuideEntry>, ) -> &mut Self

Adds guide entries after construction.

Source

pub fn argv0_names(&self) -> Vec<&str>

Returns the registered alternative argv[0] names, sorted.

Useful for install or self-healing code that iterates the names and calls Cli::create_link for each.

Creates an on-disk link in dir that lets the binary be invoked under the registered alternative argv[0] name name, using method.

target is the executable the link points at; pass None to use the current executable (std::env::current_exe), which is the common choice for install and self-healing code. The file name follows the platform and method: a symlink or hard link is <name> on Unix and <name>.exe on Windows; a Argv0LinkMethod::Script shim is <name>.cmd on Windows and an executable <name> shell script on Unix.

The call ensures the desired state idempotently: if the destination already matches what would be created (a symlink to target, a hard link with the same contents, or a shim with identical contents) it is left untouched and its path returned; if it exists but differs (wrong kind, stale target, or edited shim) it is replaced. This makes the call safe to re-run as install or self-healing code, restoring both deleted and corrupted links. The directory is created if necessary.

§Errors

Returns an error if name is not a registered route, if the current executable cannot be resolved (when target is None), or if the directory or link cannot be created or replaced (e.g. insufficient privilege for a Windows symlink, or a hard link across volumes).

Source

pub async fn run<I, S>(&self, args: I) -> CliRunOutput
where I: IntoIterator<Item = S>, S: Into<OsString> + Clone,

Runs the CLI with provided args and captures the rendered result.

Trait Implementations§

Source§

impl Clone for Cli

Source§

fn clone(&self) -> Cli

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Cli

Source§

fn fmt(&self, formatter: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl !RefUnwindSafe for Cli

§

impl !UnwindSafe for Cli

§

impl Freeze for Cli

§

impl Send for Cli

§

impl Sync for Cli

§

impl Unpin for Cli

§

impl UnsafeUnpin for Cli

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more