pub struct StrParser;Expand description
Parse the option string with given prefixs, return an ConstrctInfo.
The struct of the option string are:
[--option][=][type][!][@index]
| | | | |
| | | | |
| | | | |
| | | | The index part of option. Here are all the possible string:
| | | | @1 means first position
| | | | @-1 means last position
| | | | @[1, 2, 3] means the position 1, 2 and 3
| | | | @-[1, 2] means except the position 1, 2
| | | | @>2 means position that bigger than 2
| | | | @<3 means position less than 3
| | | | @* means all the position
| | | |
| | | Indicate the option is force required.
| | |
| | |
| | |
| | The type name of option.
| |
| The delimiter of option name and type.
|
The option name part, it must be provide by user.
Example
let parser = StrParser::default();
let ret = parser.parse("--aopt=t!".into())?;
assert_eq!(ret.name , Some(astr("--aopt")));
assert_eq!(ret.type_name, Some(astr("t")));
assert_eq!(ret.force, Some(true));
assert_eq!(ret.index, None);
let ret = parser.parse("bopt=t@[1,2,3]".into())?;
assert_eq!(ret.name , Some(astr("bopt")));
assert_eq!(ret.type_name, Some(astr("t")));
assert_eq!(ret.force, None);
assert_eq!(ret.idx(), Some(&Index::list(vec![1, 2, 3])));
For more examples, please reference test case test_option_str_parser.