Skip to main content

CommandRunner

Struct CommandRunner 

Source
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

Source

pub fn run<E, F>(matches: ArgMatches, exec: E) -> Result<(), Box<dyn Error>>
where E: FnOnce(ArgMatches, Context) -> F, F: Future<Output = CommandResult> + Send + 'static,

Runs a CLI command to completion

Sets up the command lifecycle:

  1. Creates a Cancellation token for cooperative shutdown
  2. Extracts output flags from the pre-parsed argument matches
  3. Creates an event channel and builds the Context
  4. Configures a TerminalPresenter with the parsed output flags
  5. 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 parsed ArgMatches for 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§

Source§

impl Debug for CommandRunner

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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 = !

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.