pub struct Parser<'a> { /* private fields */ }Expand description
A command-line argument parser.
§Example
use clapi::{Command, CommandOption, Argument, Context, Parser};
use clapi::validator::validate_type;
let command = Command::new("MyApp")
.option(CommandOption::new("number")
.arg(Argument::new().validator(validate_type::<i64>())))
.option(CommandOption::new("enable")
.requires_assign(true)
.arg(Argument::new().validator(validate_type::<bool>())));
let context = Context::new(command);
let result = Parser::new(&context)
.parse(vec!["--number", "25", "--enable=false"])
.unwrap();
assert_eq!(result.options().get_arg("number").unwrap().convert::<i64>().ok(), Some(25));
assert_eq!(result.options().get_arg("enable").unwrap().convert::<bool>().ok(), Some(false));Implementations§
Source§impl<'a> Parser<'a>
impl<'a> Parser<'a>
Sourcepub fn parse<S, I>(&mut self, args: I) -> Result<ParseResult>
pub fn parse<S, I>(&mut self, args: I) -> Result<ParseResult>
Parsers the given arguments and returns the Ok(ParseResult) if the parsing succeed
otherwise Err(Error).
§Example
use clapi::{Command, Argument, Parser, Context};
let command = Command::new("MyApp")
.arg(Argument::with_name("value"));
let context = Context::new(command);
let result = Parser::new(&context).parse(vec!["hello world"]).unwrap();
assert_eq!(&result.arg().unwrap()[0], "hello world");Trait Implementations§
Auto Trait Implementations§
impl<'a> !Freeze for Parser<'a>
impl<'a> !RefUnwindSafe for Parser<'a>
impl<'a> !Send for Parser<'a>
impl<'a> !Sync for Parser<'a>
impl<'a> Unpin for Parser<'a>
impl<'a> !UnwindSafe for Parser<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more