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 command line parser, this process is repeated twice. Once for the root command line parser, and a second time for the matched sub-command. The input tokens are partitioned based off the Condition parameter.

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 command line parser, this process is repeated twice. Once for the root command line parser, and a second time for the matched sub-command. The input tokens are partitioned based off the Condition parameter.

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> !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 Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.