pub struct App { /* private fields */ }Expand description
The application.
Implementations§
Source§impl App
impl App
Sourcepub fn new<S: Into<String>>(name: S) -> Self
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.
Sourcepub fn about<S: Into<String>>(self, s: S) -> Self
pub fn about<S: Into<String>>(self, s: S) -> Self
One-line description shown at the top of help.
Sourcepub fn long_about<S: Into<String>>(self, s: S) -> Self
pub fn long_about<S: Into<String>>(self, s: S) -> Self
Longer description shown in --help (long tier).
Sourcepub fn version<S: Into<String>>(self, s: S) -> Self
pub fn version<S: Into<String>>(self, s: S) -> Self
The version string reported by --version (defaults to the crate’s).
Sourcepub fn help_style(self, style: HelpStyle) -> Self
pub fn help_style(self, style: HelpStyle) -> Self
Choose a built-in help preset.
Sourcepub fn help_renderer<R: HelpRenderer>(self, r: R) -> Self
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.
Sourcepub fn theme(self, theme: Theme) -> Self
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.
Sourcepub fn command<S, F>(self, name: S, about: S, body: F) -> Self
pub fn command<S, F>(self, name: S, about: S, body: F) -> Self
Register a simple command: name, one-line about, and a body. For commands
that need arguments or flags, use App::command_with.
Sourcepub fn command_with<S, C, F>(
self,
name: S,
about: S,
configure: C,
body: F,
) -> Selfwhere
S: Into<String>,
C: FnOnce(CommandBuilder) -> CommandBuilder,
F: Fn(&Ctx) -> Result<()> + 'static,
pub fn command_with<S, C, F>(
self,
name: S,
about: S,
configure: C,
body: F,
) -> Selfwhere
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.
Sourcepub fn group<S, B>(self, name: S, about: S, build: B) -> Self
pub fn group<S, B>(self, name: S, about: S, build: B) -> Self
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.
Sourcepub fn global_flag(self, f: Flag) -> Self
pub fn global_flag(self, f: Flag) -> Self
Add an app-wide flag available to every command (beyond the built-ins).
Sourcepub fn post_run<F: Fn(&HookCtx<'_>) + 'static>(self, f: F) -> Self
pub fn post_run<F: Fn(&HookCtx<'_>) + 'static>(self, f: F) -> Self
Run after a command body that returned Ok.