Struct Args

Source
pub struct Args<'a, T = Results<'a>> {
    pub name: &'a str,
    pub path: Option<&'a str>,
    pub version: &'a str,
    pub about: &'a str,
    pub args: Vec<Arg<'a>>,
    pub disable_overrides: bool,
    pub fail_on_unknown_args: bool,
    pub subcommands: Vec<Args<'a, T>>,
    pub handler: fn(Results<'a>) -> T,
    pub filters: Filters<'a>,
}
Expand description

Struct defining the collection of args we support

Fields§

§name: &'a str

name of this command (if it’s the root) or subcommand if ommitted this will default to the cargo package name (even with subcommands)

§path: Option<&'a str>

If this subcommand is matched this field will be returned alongside the Results, with the intention that it can be used to uniquely identify which Args struct was matched (although uniqueness is not enforced). This is needed because the name field can be repeated in nested subcommands, e.g ./foo help ./foo subcommand help where “help” is the name This field is also used in the –version && –help command, so we recommend that this mirrors the cli call used, e.g if name = “subcommand” then path = “root subcommand”

§version: &'a str

The program version, used by the –version command if ommitted this will default to the cargo package version (even with subcommands)

§about: &'a str

About string included in the –help command if ommitted this will default to the cargo package description (even with subcommands)

§args: Vec<Arg<'a>>

Collections of args that we will look for under this command. Any matched will be included in the Results params or flags.

§disable_overrides: bool

Whether to fail if an arg is seen multiple times. Defaults to false

§fail_on_unknown_args: bool

Whether to fail if any unknown args are given. Defaults to false

§subcommands: Vec<Args<'a, T>>

List of subcommands underneath this command

§handler: fn(Results<'a>) -> T

handler to invoke when this command has been found. This is not called if a subcommand is invoked

§filters: Filters<'a>

Filter conditions to restrict the combinations of args this command supports

Implementations§

Source§

impl<'a, R> Args<'a, R>

Source

pub fn parse<S: IntoStr, T: IntoIterator<Item = S>>( &'a self, args: T, ) -> Result<R, Error<'a>>

Trait Implementations§

Source§

impl<'a, T: Handler<'a, T>> Default for Args<'a, T>

Source§

fn default() -> Self

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

Auto Trait Implementations§

§

impl<'a, T> Freeze for Args<'a, T>

§

impl<'a, T> RefUnwindSafe for Args<'a, T>

§

impl<'a, T> Send for Args<'a, T>

§

impl<'a, T> Sync for Args<'a, T>

§

impl<'a, T> Unpin for Args<'a, T>

§

impl<'a, T> UnwindSafe for Args<'a, T>

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<'a, T> Handler<'a, T> for T
where T: Default,

Source§

fn handler() -> fn(Results<'a>) -> T

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 = 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.