pub struct App { /* private fields */ }Expand description
Top-level application entrypoint for CLI and REPL execution.
Most embedders should start here or with AppBuilder instead of trying
to assemble runtime/session machinery directly.
Implementations§
Source§impl App
impl App
Sourcepub fn builder() -> AppBuilder
pub fn builder() -> AppBuilder
Starts the canonical public builder for host construction.
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates an application with the default native command registry and no wrapper-owned defaults.
Sourcepub fn with_native_commands(
self,
native_commands: NativeCommandRegistry,
) -> Self
pub fn with_native_commands( self, native_commands: NativeCommandRegistry, ) -> Self
Replaces the native command registry used for command dispatch.
Use this when an embedder wants extra in-process commands to participate in the same command surface as the built-in host commands. When omitted, the application uses the crate’s default native-command registry.
This is the main extension seam for downstream product crates that wrap
osp-cli and add site-specific native commands while keeping the rest
of the host/runtime behavior unchanged.
§Examples
use anyhow::Result;
use clap::Command;
use osp_cli::app::BufferedUiSink;
use osp_cli::{
App, NativeCommand, NativeCommandContext, NativeCommandOutcome, NativeCommandRegistry,
};
struct VersionCommand;
impl NativeCommand for VersionCommand {
fn command(&self) -> Command {
Command::new("version").about("Show custom version")
}
fn execute(
&self,
_args: &[String],
_context: &NativeCommandContext<'_>,
) -> Result<NativeCommandOutcome> {
Ok(NativeCommandOutcome::Exit(0))
}
}
let app = App::new().with_native_commands(
NativeCommandRegistry::new().with_command(VersionCommand),
);
let mut sink = BufferedUiSink::default();
let exit = app.run_process_with_sink(["osp", "--help"], &mut sink);
assert_eq!(exit, 0);
assert!(sink.stdout.contains("version"));Sourcepub fn with_product_defaults(self, product_defaults: ConfigLayer) -> Self
pub fn with_product_defaults(self, product_defaults: ConfigLayer) -> Self
Replaces the product-owned defaults layered into runtime bootstrap.
Use this when a wrapper crate owns extension keys such as
extensions.<site>.* and wants them resolved through the normal host
bootstrap path instead of maintaining a side-channel config helper.
When omitted, the application uses only the built-in runtime defaults.
Sourcepub fn run_from<I, T>(&self, args: I) -> Result<i32>
pub fn run_from<I, T>(&self, args: I) -> Result<i32>
Runs the application and returns a structured exit status.
Use this when your caller wants ordinary Rust error handling instead of
the process-style exit code conversion performed by
App::run_process.
§Examples
use osp_cli::App;
let exit = App::new().run_from(["osp", "--help"])?;
assert_eq!(exit, 0);Sourcepub fn with_sink<'a>(self, sink: &'a mut dyn UiSink) -> AppRunner<'a>
pub fn with_sink<'a>(self, sink: &'a mut dyn UiSink) -> AppRunner<'a>
Binds the application to a specific UI sink for repeated invocations.
Prefer this in tests, editor integrations, or foreign hosts that need
the same host behavior as osp but want the rendered text captured in a
buffer instead of written to process stdio.
§Examples
use osp_cli::app::BufferedUiSink;
use osp_cli::App;
let mut sink = BufferedUiSink::default();
let exit = App::new()
.with_sink(&mut sink)
.run_process(["osp", "--help"]);
assert_eq!(exit, 0);
assert!(!sink.stdout.is_empty());
assert!(sink.stderr.is_empty());Sourcepub fn run_with_sink<I, T>(&self, args: I, sink: &mut dyn UiSink) -> Result<i32>
pub fn run_with_sink<I, T>(&self, args: I, sink: &mut dyn UiSink) -> Result<i32>
Runs the application with the provided UI sink.
Prefer this over App::with_sink when the caller only needs one
invocation. Use App::with_sink and AppRunner when the same sink
should be reused across multiple calls.
§Examples
use osp_cli::App;
use osp_cli::app::BufferedUiSink;
let mut sink = BufferedUiSink::default();
let exit = App::new().run_with_sink(["osp", "--help"], &mut sink)?;
assert_eq!(exit, 0);
assert!(!sink.stdout.is_empty());
assert!(sink.stderr.is_empty());Sourcepub fn run_process<I, T>(&self, args: I) -> i32
pub fn run_process<I, T>(&self, args: I) -> i32
Runs the application and converts execution failures into process exit codes.
Use this when the caller wants osp-style process behavior rather than
structured error propagation. User-facing failures are rendered to the
process stdio streams before the exit code is returned.
§Examples
use osp_cli::App;
let exit = App::new().run_process(["osp", "--help"]);
assert_eq!(exit, 0);Sourcepub fn run_process_with_sink<I, T>(&self, args: I, sink: &mut dyn UiSink) -> i32
pub fn run_process_with_sink<I, T>(&self, args: I, sink: &mut dyn UiSink) -> i32
Runs the application with the provided sink and returns a process exit code.
This mirrors App::run_process but writes all rendered output and
user-facing errors through the supplied sink instead of touching process
stdio.
§Examples
use osp_cli::App;
use osp_cli::app::BufferedUiSink;
let mut sink = BufferedUiSink::default();
let exit = App::new().run_process_with_sink(["osp", "--help"], &mut sink);
assert_eq!(exit, 0);
assert!(!sink.stdout.is_empty());
assert!(sink.stderr.is_empty());Trait Implementations§
Auto Trait Implementations§
impl Freeze for App
impl !RefUnwindSafe for App
impl Send for App
impl Sync for App
impl Unpin for App
impl UnsafeUnpin for App
impl !UnwindSafe for App
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<D> OwoColorize for D
impl<D> OwoColorize for D
Source§fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
Source§fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
Source§fn black(&self) -> FgColorDisplay<'_, Black, Self>
fn black(&self) -> FgColorDisplay<'_, Black, Self>
Source§fn on_black(&self) -> BgColorDisplay<'_, Black, Self>
fn on_black(&self) -> BgColorDisplay<'_, Black, Self>
Source§fn red(&self) -> FgColorDisplay<'_, Red, Self>
fn red(&self) -> FgColorDisplay<'_, Red, Self>
Source§fn on_red(&self) -> BgColorDisplay<'_, Red, Self>
fn on_red(&self) -> BgColorDisplay<'_, Red, Self>
Source§fn green(&self) -> FgColorDisplay<'_, Green, Self>
fn green(&self) -> FgColorDisplay<'_, Green, Self>
Source§fn on_green(&self) -> BgColorDisplay<'_, Green, Self>
fn on_green(&self) -> BgColorDisplay<'_, Green, Self>
Source§fn yellow(&self) -> FgColorDisplay<'_, Yellow, Self>
fn yellow(&self) -> FgColorDisplay<'_, Yellow, Self>
Source§fn on_yellow(&self) -> BgColorDisplay<'_, Yellow, Self>
fn on_yellow(&self) -> BgColorDisplay<'_, Yellow, Self>
Source§fn blue(&self) -> FgColorDisplay<'_, Blue, Self>
fn blue(&self) -> FgColorDisplay<'_, Blue, Self>
Source§fn on_blue(&self) -> BgColorDisplay<'_, Blue, Self>
fn on_blue(&self) -> BgColorDisplay<'_, Blue, Self>
Source§fn magenta(&self) -> FgColorDisplay<'_, Magenta, Self>
fn magenta(&self) -> FgColorDisplay<'_, Magenta, Self>
Source§fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
Source§fn purple(&self) -> FgColorDisplay<'_, Magenta, Self>
fn purple(&self) -> FgColorDisplay<'_, Magenta, Self>
Source§fn on_purple(&self) -> BgColorDisplay<'_, Magenta, Self>
fn on_purple(&self) -> BgColorDisplay<'_, Magenta, Self>
Source§fn cyan(&self) -> FgColorDisplay<'_, Cyan, Self>
fn cyan(&self) -> FgColorDisplay<'_, Cyan, Self>
Source§fn on_cyan(&self) -> BgColorDisplay<'_, Cyan, Self>
fn on_cyan(&self) -> BgColorDisplay<'_, Cyan, Self>
Source§fn white(&self) -> FgColorDisplay<'_, White, Self>
fn white(&self) -> FgColorDisplay<'_, White, Self>
Source§fn on_white(&self) -> BgColorDisplay<'_, White, Self>
fn on_white(&self) -> BgColorDisplay<'_, White, Self>
Source§fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
Source§fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
Source§fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
Source§fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
Source§fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
Source§fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
Source§fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
Source§fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
Source§fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
Source§fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
Source§fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
Source§fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
Source§fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
Source§fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
Source§fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
Source§fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
Source§fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
Source§fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
Source§fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
Source§fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
Source§fn bold(&self) -> BoldDisplay<'_, Self>
fn bold(&self) -> BoldDisplay<'_, Self>
Source§fn dimmed(&self) -> DimDisplay<'_, Self>
fn dimmed(&self) -> DimDisplay<'_, Self>
Source§fn italic(&self) -> ItalicDisplay<'_, Self>
fn italic(&self) -> ItalicDisplay<'_, Self>
Source§fn underline(&self) -> UnderlineDisplay<'_, Self>
fn underline(&self) -> UnderlineDisplay<'_, Self>
Source§fn blink(&self) -> BlinkDisplay<'_, Self>
fn blink(&self) -> BlinkDisplay<'_, Self>
Source§fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
Source§fn reversed(&self) -> ReversedDisplay<'_, Self>
fn reversed(&self) -> ReversedDisplay<'_, Self>
Source§fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
Source§fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::fg or
a color-specific method, such as OwoColorize::green, Read moreSource§fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::bg or
a color-specific method, such as OwoColorize::on_yellow, Read more