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
impl Cli
Sourcepub fn middleware(&self) -> &Middleware
pub fn middleware(&self) -> &Middleware
Returns the shared middleware template.
Sourcepub fn middleware_mut(&mut self) -> &mut Middleware
pub fn middleware_mut(&mut self) -> &mut Middleware
Returns mutable middleware for advanced application setup.
Sourcepub async fn execute(&self) -> ExitCode
pub async fn execute(&self) -> ExitCode
Executes the CLI with process arguments and process stdout/stderr.
Sourcepub async fn execute_from<I, S, O, E>(
&self,
args: I,
stdout: &mut O,
stderr: &mut E,
) -> Result<ExitCode>
pub async fn execute_from<I, S, O, E>( &self, args: I, stdout: &mut O, stderr: &mut E, ) -> Result<ExitCode>
Executes the CLI with caller-provided args and output writers.
Sourcepub async fn execute_from_until_signal<I, S, O, E, Shutdown>(
&self,
args: I,
stdout: &mut O,
stderr: &mut E,
shutdown: Shutdown,
) -> Result<ExitCode>
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>
Executes the CLI until either command completion or a shutdown signal future resolves.
Sourcepub fn register_auth_provider(
&mut self,
provider: Arc<dyn AuthProvider>,
) -> &mut Self
pub fn register_auth_provider( &mut self, provider: Arc<dyn AuthProvider>, ) -> &mut Self
Registers an auth provider after construction.
Sourcepub fn root_command(&self) -> &Command
pub fn root_command(&self) -> &Command
Returns the built clap root command.
Sourcepub fn add_module_group(
&mut self,
category: impl Into<String>,
group: RuntimeGroupSpec,
) -> &mut Self
pub fn add_module_group( &mut self, category: impl Into<String>, group: RuntimeGroupSpec, ) -> &mut Self
Adds one runtime module group after construction.
Sourcepub fn add_module(&mut self, module: Module) -> &mut Self
pub fn add_module(&mut self, module: Module) -> &mut Self
Adds one module after construction.
Sourcepub fn add_command(&mut self, command: RuntimeCommandSpec) -> &mut Self
pub fn add_command(&mut self, command: RuntimeCommandSpec) -> &mut Self
Adds one top-level runtime command after construction.
Sourcepub fn set_has_guide(&mut self, has_guide: bool) -> &mut Self
pub fn set_has_guide(&mut self, has_guide: bool) -> &mut Self
Controls whether the built-in guide command is advertised.
Sourcepub fn add_guides(
&mut self,
entries: impl IntoIterator<Item = GuideEntry>,
) -> &mut Self
pub fn add_guides( &mut self, entries: impl IntoIterator<Item = GuideEntry>, ) -> &mut Self
Adds guide entries after construction.
Sourcepub fn argv0_names(&self) -> Vec<&str>
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.
Sourcepub fn create_link(
&self,
name: &str,
dir: impl AsRef<Path>,
target: Option<&Path>,
method: Argv0LinkMethod,
) -> Result<PathBuf>
pub fn create_link( &self, name: &str, dir: impl AsRef<Path>, target: Option<&Path>, method: Argv0LinkMethod, ) -> Result<PathBuf>
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).
Sourcepub async fn run<I, S>(&self, args: I) -> CliRunOutput
pub async fn run<I, S>(&self, args: I) -> CliRunOutput
Runs the CLI with provided args and captures the rendered result.