pub struct Arguments { /* private fields */ }Expand description
A parsed command line.
Implementations§
Source§impl Arguments
impl Arguments
Sourcepub fn parse<I, S>(argv: I) -> Self
pub fn parse<I, S>(argv: I) -> Self
Parse an argument list, without the program name.
The first positional word is the command; the rest belong to it.
Sourcepub fn positional(&self) -> &[String]
pub fn positional(&self) -> &[String]
The positional arguments after the command.
Sourcepub fn argument(&self, index: usize) -> Option<&str>
pub fn argument(&self, index: usize) -> Option<&str>
The positional argument at index, after the command.
Sourcepub fn option(&self, name: &str) -> Option<&str>
pub fn option(&self, name: &str) -> Option<&str>
An option’s value.
Options are --name=value. A bare --name is a flag, so
--port 8000 gives a flag called port and a stray positional
8000 — and the value goes nowhere.
That form cannot be supported without knowing which options take a
value (--verbose migrate is a flag and a command, not an option), so
instead it is reported: asking for an option that was given as a
bare flag warns and says what to write. Serving on the wrong port
because a = was missing is a bad afternoon.
Sourcepub fn option_or<'a>(&'a self, name: &str, default: &'a str) -> &'a str
pub fn option_or<'a>(&'a self, name: &str, default: &'a str) -> &'a str
An option’s value, or default.
Sourcepub fn parsed_or<T: FromStr>(&self, name: &str, default: T) -> T
pub fn parsed_or<T: FromStr>(&self, name: &str, default: T) -> T
An option parsed into T, or default if absent or unparsable.
Sourcepub fn is_valueless(&self, name: &str) -> bool
pub fn is_valueless(&self, name: &str) -> bool
Whether name was given as a bare flag when a value was wanted.
What option warns about, exposed so a command can
refuse rather than carry on with a default.
Sourcepub fn wants_help(&self) -> bool
pub fn wants_help(&self) -> bool
Whether help was asked for, in any of its usual spellings.