Skip to main content

LauncherWithSubs

Struct LauncherWithSubs 

Source
pub struct LauncherWithSubs<G: Command> { /* private fields */ }
Expand description

Launcher that already has at least one subcommand registered.

Implementations§

Source§

impl<G: Command + 'static> LauncherWithSubs<G>

Source

pub fn command<S>(self, name: &str) -> Self
where S: Command + SubCommandOf<G> + 'static,

Register a subcommand. S must implement Command (for parsing) and SubCommandOf<G> (for running with access to the parsed global options).

Source

pub fn command_with_description<S>(self, name: &str, description: &str) -> Self
where S: Command + SubCommandOf<G> + 'static,

Like LauncherWithSubs::command but overrides the help description for the registered subcommand (otherwise S::schema().description is used). Primarily called by #[derive(Command)] on enums when a variant carries its own #[command(description = "...")] or doc comment.

Source

pub fn schema(&self) -> CommandSchema

Return the combined root + subcommand schema. Useful for tests and for introspection (e.g. generating shell completions in the future). Panics on the same invariants as execution — don’t call this from production code if those might fire.

Source

pub fn run_args(&self, args: &[String]) -> Result<()>

Parse args and run the matched subcommand. Use this in tests to exercise the launcher without touching the process environment.

Source

pub fn execute(self) -> !

Parse std::env::args(), dispatch to the matching subcommand, and exit. Prints help on --help and parse error messages to stderr before exiting. When the subcommand’s own run returns an error (wrapped in Error::Runtime by the registered runner), that is treated as a runtime failure (exit code 1) without printing help, so legitimate runtime errors aren’t reported as bad CLI syntax — even when the subcommand reuses parse-origin Error variants for its own post-parse validation.

Auto Trait Implementations§

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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, 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.