Skip to main content

App

Struct App 

Source
pub struct App { /* private fields */ }
Expand description

The application.

Implementations§

Source§

impl App

Source

pub fn new<S: Into<String>>(name: S) -> Self

Start a new app with the given program name.

The version defaults to Cornerstone’s own crate version, which is almost never what you want. Set your tool’s version explicitly with App::version, typically .version(env!("CARGO_PKG_VERSION")) so it tracks your crate — env! must be expanded in your crate, not here, to pick up your version rather than the library’s.

Source

pub fn about<S: Into<String>>(self, s: S) -> Self

One-line description shown at the top of help.

Source

pub fn long_about<S: Into<String>>(self, s: S) -> Self

Longer description shown in --help (long tier).

Source

pub fn version<S: Into<String>>(self, s: S) -> Self

The version string reported by --version (defaults to the crate’s).

Source

pub fn help_style(self, style: HelpStyle) -> Self

Choose a built-in help preset.

Source

pub fn help_renderer<R: HelpRenderer>(self, r: R) -> Self

Supply a fully custom help renderer, overriding the preset. Use this when none of the three built-in presets fit the look you want.

Source

pub fn theme(self, theme: Theme) -> Self

Install a custom Theme. Every glyph, label, and color the library emits is read from it. Called once; defaults are neutral.

Source

pub fn command<S, F>(self, name: S, about: S, body: F) -> Self
where S: Into<String>, F: Fn(&Ctx) -> Result<()> + 'static,

Register a simple command: name, one-line about, and a body. For commands that need arguments or flags, use App::command_with.

Source

pub fn command_with<S, C, F>( self, name: S, about: S, configure: C, body: F, ) -> Self
where S: Into<String>, C: FnOnce(CommandBuilder) -> CommandBuilder, F: Fn(&Ctx) -> Result<()> + 'static,

Register a command, configuring its spec (args, flags, examples) through a builder closure before attaching the body.

Source

pub fn group<S, B>(self, name: S, about: S, build: B) -> Self
where S: Into<String>, B: FnOnce(Group) -> Group,

Register a command group: a subcommand that itself contains subcommands (e.g. tool remote add). The build closure receives a Group to attach child commands to. Invoking the group bare prints its help.

Source

pub fn global_flag(self, f: Flag) -> Self

Add an app-wide flag available to every command (beyond the built-ins).

Source

pub fn pre_run<F: Fn(&HookCtx<'_>) + 'static>(self, f: F) -> Self

Run before any command body.

Source

pub fn post_run<F: Fn(&HookCtx<'_>) + 'static>(self, f: F) -> Self

Run after a command body that returned Ok.

Source

pub fn on_error<F: Fn(&Error) + 'static>(self, f: F) -> Self

Run when a command body returns Err, before the process exits.

Source

pub fn run(self) -> !

Parse std::env::args and run. Never returns — calls exit.

Source

pub fn run_with(self, args: Vec<String>) -> i32

Testable entry point: run against an explicit argument vector and return the exit code instead of exiting.

Auto Trait Implementations§

§

impl !RefUnwindSafe for App

§

impl !Send for App

§

impl !Sync for App

§

impl !UnwindSafe for App

§

impl Forget for App

§

impl Freeze for App

§

impl Move for App

§

impl Unpin for App

§

impl UnsafeUnpin for App

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

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.