GeneralParser

Struct GeneralParser 

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

The configured command line parser. Built via CommandLineParser::build or SubCommandParser::build.

Implementations§

Source§

impl<'a> GeneralParser<'a>

Source

pub fn parse_tokens(self, tokens: &[&str]) -> Result<(), i32>

Run the command line parser against the input tokens. Help messages are printed on stdout, while error messages are printed on stderr.

The parser will process the input tokens based off the CommandLineParser/SubCommandParser configuration. Parsing happens in two phases:

  1. Token matching aligns the tokens to arguments and options. All tokens must be matched successfully in order to proceed to the next phase.
  2. Token capturing parses the tokens by their respective types T. This phase will actually mutate your program variables.

If at any point the parser encounters an error (ex: un-matched token, un-capturable token, etc), it will return with Err(1).

If the help switch (-h or --help) is encountered, the parser will display the help message and return with Err(0). This skips the phase #2 capturing.

In the case of a sub-command based parser, a third phase is introduced where the parser is branched into the sub-command. After branching, the token matching and token capturing phases are repeated for the sub-command. In effect, the input tokens are partitioned based off the branching Condition.

Source

pub fn parse(self)

Run the command line parser against the Cli env::args. Help messages are printed on stdout, while error messages are printed on stderr.

The parser will process the input tokens based off the CommandLineParser/SubCommandParser configuration. Parsing happens in two phases:

  1. Token matching aligns the tokens to arguments and options. All tokens must be matched successfully in order to proceed to the next phase.
  2. Token capturing parses the tokens by their respective types T. This phase will actually mutate your program variables.

If at any point the parser encounters an error (ex: un-matched token, un-capturable token, etc), it will exit with error code 1 (via std::process::exit).

If the help switch (-h or --help) is encountered, the parser will display the help message and exit with error code 0. This skips the phase #2 capturing.

In the case of a sub-command based parser, a third phase is introduced where the parser is branched into the sub-command. After branching, the token matching and token capturing phases are repeated for the sub-command. In effect, the input tokens are partitioned based off the branching Condition.

Trait Implementations§

Source§

impl<'a> Debug for GeneralParser<'a>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for GeneralParser<'a>

§

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

§

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

§

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

§

impl<'a> Unpin for GeneralParser<'a>

§

impl<'a> !UnwindSafe for GeneralParser<'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> 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 = 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.