Skip to main content

CliMain

Struct CliMain 

Source
pub struct CliMain<'a, C> { /* private fields */ }
Expand description

The whole lifecycle of a registry-compiled CLI, from main.

build registry ─ bind actions ─ resolve argv ─ check ─ project
    ─ install --stdout-file/--stderr-file ─ help | version | docs | run
    ─ settle write failures ─ exit code

Each step’s failure has one report. A registry that does not build or bind is cli_spec_invalid / cli_actions_invalid (exit 1); a rejected argv is its CliError code; a check or a handler may stop with a CliStop. All of those happen before a sink is opened and are reported as strict JSON on stderr, so a refused call never creates a redirect file. Then the sinks are installed (output_setup_failed if they cannot be, or if this build has no stream-redirect and one was asked for), and help, version and docs are answered. A run calls execute with the handler’s command, the invocation and an emitter built from the plan; that emitter is the only route to stdout and stderr, raw bytes included. Whatever execute returns is settled against what the emitter wrote: a closed reader is exit 0, any other failed write exit 4 with output_write_failed.

Implementations§

Source§

impl<'a, C> CliMain<'a, C>

Source

pub fn new<I, S>( cli: Result<BuiltCliSpec, CliSpecError>, actions: impl FnOnce(&BuiltCliSpec) -> I, ) -> Self
where I: IntoIterator<Item = (S, CliHandler<C>)>, S: Into<String>,

Bind actions — built from the registry, for a program whose handler table depends on it — to cli.

Source

pub fn check( self, hook: impl FnOnce(&BoundOutcome<Result<C, CliStop>>) -> Result<(), CliStop> + 'a, ) -> Self

Run hook on every resolved outcome before anything is projected or opened: capability checks that depend on how the program was started, and argument constraints that span the whole program. A refusal is reported and no sink is created.

Source

pub fn version(self, event: impl FnOnce(&ResolvedVersion) -> Event + 'a) -> Self

Answer --version with this event instead of cli_version_event: for a program whose version identity has more to it than the registry carries, such as the protocol versions it speaks. Build it from crate::build_cli_version’s fields so the standard ones stay.

Source

pub fn run<A, T>( self, argv: A, execute: impl FnOnce(C, &ResolvedInvocation, &mut ProcessEmitter) -> Result<u8, CliStop>, ) -> ExitCode
where A: IntoIterator<Item = T>, T: Into<OsString>,

Resolve argv and carry the call through to its exit code.

Source

pub fn prepare<A, T>(self, argv: A) -> Result<PreparedCli<C>, ExitCode>
where A: IntoIterator<Item = T>, T: Into<OsString>,

Resolve argv and install output sinks, or complete a lifecycle response.

An exit code represents a completed help, version, or documentation response, or an error reported during preparation.

Auto Trait Implementations§

§

impl<'a, C> !RefUnwindSafe for CliMain<'a, C>

§

impl<'a, C> !Send for CliMain<'a, C>

§

impl<'a, C> !Sync for CliMain<'a, C>

§

impl<'a, C> !UnwindSafe for CliMain<'a, C>

§

impl<'a, C> Forget for CliMain<'a, C>

§

impl<'a, C> Freeze for CliMain<'a, C>

§

impl<'a, C> Move for CliMain<'a, C>

§

impl<'a, C> Unpin for CliMain<'a, C>
where *const u8 is !null: Unpin, *const LeafNode<String, FixedValue> is !null: Unpin, Box<(String, FixedValue)>: Unpin, *const LeafNode<Vec<String>, BTreeSet<String>> is !null: Unpin, Box<(Vec<String>, BTreeSet<String>)>: Unpin, *const LeafNode<String, fn(&ResolvedInvocation) -> Result<C, CliStop>> is !null: Unpin, Box<(String, fn(&ResolvedInvocation) -> Result<C, CliStop>)>: Unpin, *const LeafNode<String, Value> is !null: Unpin, Box<(String, Value)>: Unpin, Box<dyn FnOnce(&BoundOutcome<Result<C, CliStop>>) -> Result<(), CliStop> + 'a>: Unpin, Box<dyn FnOnce(&ResolvedVersion) -> Event + 'a>: Unpin,

§

impl<'a, C> UnsafeUnpin for CliMain<'a, C>

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

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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, !>

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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more