[go: up one dir, main page]

App

Struct App 

Source
pub struct App<'a> { /* private fields */ }
Expand description

The main object used to represent the program.

All consumers of the crate need to create a single object of this type.

Implementations§

Source§

impl<'a> App<'a>

Source

pub fn new(name: &str) -> Self

Create a new application object.

Source

pub fn args(self, args: Args) -> Self

Specify a set of argument handlers to parse the command-line with.

Source

pub fn version(self, version: &str) -> Self

Specify the version of the program.

Source

pub fn summary(self, summary: &str) -> Self

Specify brief explanatory text for the program.

Source

pub fn help(self, help: &str) -> Self

Specify extended usage information for the program.

Source

pub fn notes(self, notes: &str) -> Self

Specify notes for the program.

Source

pub fn settings(self, settings: Settings) -> Self

Specify any settings for the program.

Source

pub fn ignore_unknown_options(self) -> Self

If set, don’t error if unknown options are specified - just ignore them.

§Note

This is an alternative to calling the settings() method.

Source

pub fn ignore_unknown_posn_args(self) -> Self

If set, don’t error if unknown positional arguments are specified - just ignore them.

§Note

This is an alternative to calling the settings() method.

Source

pub fn no_strict_options(self) -> Self

If set, disallow option values from starting with as dash.

See the Settings method of the same name for full details and an example showing the effect of this call.

§Note

This is an alternative to calling the settings() method.

Source

pub fn generate_help<W>(&self, writer: &mut W) -> Result<()>
where W: Write + Send + Sync + 'static,

Generate a help/usage statement from the registered Arg’s.

This is called automatically when the user specifies -h anywhere on the command line; you do not need to register an Arg for -h.

Source

pub fn parse_with_args(&mut self, cli_args: Vec<String>) -> Result<()>

Parse a set of command line arguments (without the program name).

§Arguments
  • cli_args: Vector of string arguments. Specify your own, or call get_args().
§Notes
  • The cli_args vector must not specify the command name (which by default is returned as the first element by env::args().collect() for example. Use get_args() as this handles this for you.
Source

pub fn handler(self, boxed_handler: Box<dyn Handler + 'a>) -> Self

Specify the handler for the option which must implement the Handler trait.

§Note

If the handler needs to modify its own state when called, the specified boxed trait must provide a mutable reference.

Source

pub fn parse(&mut self) -> Result<()>

Simplest interface to the parser.

Trait Implementations§

Source§

impl<'a> Clone for App<'a>

Source§

fn clone(&self) -> App<'a>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> Debug for App<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'a> Default for App<'a>

Source§

fn default() -> App<'a>

Returns the “default value” for a type. Read more
Source§

impl<'a> PartialEq for App<'a>

Source§

fn eq(&self, other: &App<'a>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'a> StructuralPartialEq for App<'a>

Auto Trait Implementations§

§

impl<'a> Freeze for App<'a>

§

impl<'a> !RefUnwindSafe for App<'a>

§

impl<'a> !Send for App<'a>

§

impl<'a> !Sync for App<'a>

§

impl<'a> Unpin for App<'a>

§

impl<'a> !UnwindSafe for App<'a>

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.