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>
impl<G: Command + 'static> LauncherWithSubs<G>
Sourcepub fn command<S>(self, name: &str) -> Selfwhere
S: Command + SubCommandOf<G> + 'static,
pub fn command<S>(self, name: &str) -> Selfwhere
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).
Sourcepub fn command_with_description<S>(self, name: &str, description: &str) -> Selfwhere
S: Command + SubCommandOf<G> + 'static,
pub fn command_with_description<S>(self, name: &str, description: &str) -> Selfwhere
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.
Sourcepub fn schema(&self) -> CommandSchema
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.
Sourcepub fn run_args(&self, args: &[String]) -> Result<()>
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.
Sourcepub fn execute(self) -> !
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.