pub struct CommandRunner;Expand description
CLI command runner
Encapsulates the lifecycle of running a CLI command: creating the event channel, constructing
the Context, registering signal handlers, and presenting output through a
TerminalPresenter. The main!() macro dispatches to CommandRunner::run when the
resolved leaf is a ResolvedLeaf::Command.
§Examples
// This is what main!() expands to for commands:
ResolvedLeaf::Command { matches, exec } => {
clawless::runner::CommandRunner::run(matches, exec)
}Implementations§
Source§impl CommandRunner
impl CommandRunner
Sourcepub fn run<E, F>(matches: ArgMatches, exec: E) -> Result<(), Box<dyn Error>>
pub fn run<E, F>(matches: ArgMatches, exec: E) -> Result<(), Box<dyn Error>>
Runs a CLI command to completion
Sets up the command lifecycle:
- Detects whether a user is present who can answer the application
- Creates a
Cancellationtoken for cooperative shutdown - Extracts output flags from the pre-parsed argument matches
- Creates an event channel and builds the
Context - Configures a
TerminalPresenterwith the parsed output flags - Creates a Tokio runtime, spawns the signal handler, and runs the command through the presenter
A user is present when the standard input and the standard error are both terminals. The
Context carries the result as its Interactivity.
Output flags (--quiet, --verbose, --json) are augmented at the root level by
main!() with .global(true), so they are available in every leaf’s ArgMatches.
§Arguments
matches— The parsedArgMatchesfor this command leaf, as resolved by the subcommand tree walk.exec— Executes the command with the given matches and context. The#[command]macro generates a function for this, and any other callable works. A caller that builds its command tree at run time passes a closure that owns the command it resolved.
§Errors
Returns an error if context construction fails (e.g., the current working directory cannot be determined), if the Tokio runtime cannot be created, or if the command itself fails.