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 codeEach 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>
impl<'a, C> CliMain<'a, C>
Sourcepub fn new<I, S>(
cli: Result<BuiltCliSpec, CliSpecError>,
actions: impl FnOnce(&BuiltCliSpec) -> I,
) -> Self
pub fn new<I, S>( cli: Result<BuiltCliSpec, CliSpecError>, actions: impl FnOnce(&BuiltCliSpec) -> I, ) -> Self
Bind actions — built from the registry, for a program whose handler
table depends on it — to cli.
Sourcepub fn check(
self,
hook: impl FnOnce(&BoundOutcome<Result<C, CliStop>>) -> Result<(), CliStop> + 'a,
) -> Self
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.
Sourcepub fn version(self, event: impl FnOnce(&ResolvedVersion) -> Event + 'a) -> Self
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.
Sourcepub fn run<A, T>(
self,
argv: A,
execute: impl FnOnce(C, &ResolvedInvocation, &mut ProcessEmitter) -> Result<u8, CliStop>,
) -> ExitCode
pub fn run<A, T>( self, argv: A, execute: impl FnOnce(C, &ResolvedInvocation, &mut ProcessEmitter) -> Result<u8, CliStop>, ) -> ExitCode
Resolve argv and carry the call through to its exit code.
Sourcepub fn prepare<A, T>(self, argv: A) -> Result<PreparedCli<C>, ExitCode>
pub fn prepare<A, T>(self, argv: A) -> Result<PreparedCli<C>, ExitCode>
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.