Skip to main content

standout_dispatch/
lib.rs

1//! Command dispatch and orchestration for clap-based CLIs.
2//!
3//! Routes parsed `ArgMatches` to a [`Handler`], running pre-dispatch, handler,
4//! post-dispatch, and post-output hooks around it, and returns typed
5//! [`HandlerResult`] data — presentation stays with the consuming framework.
6//! A handler adapter takes `(&ArgMatches, &CommandContext)` and returns
7//! serializable data, so application logic stays reusable outside a CLI. The
8//! third parameter of [`Handler::handle`] is the typed results channel of
9//! [`results`]; a batch command sets `Handler::Event` to [`NoEvents`] and
10//! ignores it, and a command that produces its result while it runs takes the
11//! channel as a third closure parameter through [`EventsFnHandler`].
12//!
13//! [`CommandContext`] carries two kinds of injected state: `app_state` is
14//! immutable and app-lifetime (database, config, API clients), built once
15//! and shared via `Rc`; `extensions` is mutable and per-request, set by
16//! pre-dispatch hooks for things like a resolved user session.
17
18pub mod artifact;
19mod contract;
20mod diagnostic;
21mod dispatch;
22mod handler;
23mod hooks;
24mod results;
25mod stream;
26pub mod verify;
27pub use artifact::{Artifact, ArtifactDestination, ArtifactReceipt, ArtifactRun};
28pub use contract::{ContractSurface, Envelope};
29pub use diagnostic::{Diagnostic, DiagnosticKind, DiagnosticPosition, DiagnosticRange, Severity};
30pub use dispatch::{
31    extract_command_path, get_deepest_matches, has_subcommand, insert_default_command,
32    path_to_string, string_to_path,
33};
34pub use handler::{
35    AppFailure, CommandContext, DispatchResult, EventsFnHandler, ExitStatus, Extensions,
36    ExternalFailure, FnHandler, Handler, HandlerOutcome, HandlerResult, IntoHandlerResult,
37    IntoSummaryResult, InvalidAppStatus, InvalidExternalStatus, Output, OutputKind, RunError,
38    RunErrorKind, RunOutput, SimpleFnHandler, SuccessKind, Summary, SummaryResult,
39};
40pub use hooks::{
41    ArtifactOutput, HookError, HookPhase, Hooks, PostDispatchFn, PostOutputFn, PreDispatchFn,
42    RenderedOutput, TextOutput,
43};
44pub use results::{emits_events, Delivery, EmitError, EventSink, NoEvents, Results, RunRecorder};
45pub use stream::{StreamCapture, StreamSink};