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>
impl<'a> GeneralParser<'a>
Sourcepub fn parse_tokens(self, tokens: &[&str]) -> Result<(), i32>
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:
- Token matching aligns the tokens to arguments and options. All tokens must be matched successfully in order to proceed to the next phase.
- 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.
Sourcepub fn parse(self)
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:
- Token matching aligns the tokens to arguments and options. All tokens must be matched successfully in order to proceed to the next phase.
- 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.