pub struct Named { /* private fields */ }
Expand description
A named thing used to create Flag, Switch or Argument.
Implementations
sourceimpl Named
impl Named
sourcepub fn short(self, short: char) -> Self
pub fn short(self, short: char) -> Self
Add a short name to a flag/switch/argument
You can specify it multiple times, items past the first one represent hidden aliases.
let switch: Parser<bool> =
short('f')
.short('F')
.long("flag")
.help("a flag that does a thing")
.switch();
sourcepub fn long(self, long: &'static str) -> Self
pub fn long(self, long: &'static str) -> Self
Add a long name to a flag/switch/argument
You can specify it multiple times, items past the first one will become a hidden aliases.
let switch: Parser<bool> =
short('f')
.long("flag")
.long("Flag")
.help("a flag that does a thing")
.switch();
sourcepub fn help<M>(self, help: M) -> Self where
M: Into<String>,
pub fn help<M>(self, help: M) -> Self where
M: Into<String>,
Add a help message to a flag/switch/argument
let switch: Parser<bool> =
short('f')
.long("flag")
.help("a flag that does a thing")
.switch();
sourcepub fn switch(self) -> Parser<bool>
pub fn switch(self) -> Parser<bool>
Simple boolean flag
Parser produces true
if flag is present in a command line or false
otherwise
let switch: Parser<bool> =
short('f')
.long("flag")
.help("a flag that does a thing")
.switch();
sourcepub fn flag<T>(self, present: T, absent: T) -> Parser<T> where
T: Clone + 'static,
pub fn flag<T>(self, present: T, absent: T) -> Parser<T> where
T: Clone + 'static,
Flag with custom present/absent values
Parser produces present
if flag is present in a command line or absent
otherwise
#[derive(Clone)]
enum Flag {
Absent,
Present,
}
let switch: Parser<Flag> =
short('f')
.long("flag")
.help("a flag that does a thing")
.flag(Flag::Present, Flag::Absent);
sourcepub fn req_flag<T>(self, present: T) -> Parser<T> where
T: Clone + 'static,
pub fn req_flag<T>(self, present: T) -> Parser<T> where
T: Clone + 'static,
Required flag with custom value
Parser produces a value if present and fails otherwise. Designed to be used with combination of other parser(s).
#[derive(Clone)]
enum Decision {
On,
Off,
Undecided
}
let on = long("on").req_flag(Decision::On);
let off = long("off").req_flag(Decision::Off);
// Requires user to specify either `--on` or `--off`
let state: Parser<Decision> = on.or_else(off).fallback(Decision::Undecided);
// counts how many times flag `-v` is given on a command line
let verbosity: Parser<usize> = short('v').req_flag(()).many().map(|v| v.len());
sourcepub fn argument(self, metavar: &'static str) -> Parser<String>
pub fn argument(self, metavar: &'static str) -> Parser<String>
Named argument that can be encoded as String
Argument must be present (but can be made into Option
using
optional
) and it must contain only valid unicode characters.
For OS specific encoding see argument_os
.
let arg = short('n').long("name").argument("NAME");
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for Named
impl Send for Named
impl Sync for Named
impl Unpin for Named
impl UnwindSafe for Named
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more