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:
- 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
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.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for CommandRunner
impl RefUnwindSafe for CommandRunner
impl Send for CommandRunner
impl Sync for CommandRunner
impl Unpin for CommandRunner
impl UnsafeUnpin for CommandRunner
impl UnwindSafe for CommandRunner
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more