pub struct Matches { /* private fields */ }Available on crate feature
std only.Expand description
Parsed arguments for one command level.
Read flags with flag, option and positional values with
value, and descend into an invoked subcommand with
subcommand.
§Examples
use cli_forge::{App, Arg, Command};
let mut app = App::new("demo");
app.register(
Command::new("build")
.arg(Arg::flag("release").short('r'))
.arg(Arg::option("jobs").short('j').default("1")),
);
let matches = app.try_parse_from(["build", "-r", "--jobs", "8"]).unwrap();
let (name, build) = matches.subcommand().unwrap();
assert_eq!(name, "build");
assert!(build.flag("release"));
assert_eq!(build.value("jobs"), Some("8"));Implementations§
Source§impl Matches
impl Matches
Sourcepub fn flag(&self, name: &str) -> bool
pub fn flag(&self, name: &str) -> bool
Whether the flag named name was set.
Returns false for an unset flag or an unknown name.
§Examples
use cli_forge::{App, Arg, Command};
let mut app = App::new("demo");
app.register(Command::new("run").arg(Arg::flag("verbose").short('v')));
let m = app.try_parse_from(["run", "-v"]).unwrap();
assert!(m.subcommand().unwrap().1.flag("verbose"));Sourcepub fn value(&self, name: &str) -> Option<&str>
pub fn value(&self, name: &str) -> Option<&str>
The value given for an option or positional named name, or its default.
Returns None if the argument was not provided and has no default, or if
the name is unknown.
§Examples
use cli_forge::{App, Arg, Command};
let mut app = App::new("demo");
app.register(Command::new("greet").arg(Arg::positional("name").default("world")));
let provided = app.try_parse_from(["greet", "Ada"]).unwrap();
assert_eq!(provided.subcommand().unwrap().1.value("name"), Some("Ada"));
let defaulted = app.try_parse_from(["greet"]).unwrap();
assert_eq!(defaulted.subcommand().unwrap().1.value("name"), Some("world"));Sourcepub fn subcommand(&self) -> Option<(&str, &Matches)>
pub fn subcommand(&self) -> Option<(&str, &Matches)>
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Matches
impl RefUnwindSafe for Matches
impl Send for Matches
impl Sync for Matches
impl Unpin for Matches
impl UnsafeUnpin for Matches
impl UnwindSafe for Matches
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