pub struct Options { /* private fields */ }
Expand description
A description of the options that a program can handle.
Implementations§
Source§impl Options
impl Options
Sourcepub fn parsing_style(&mut self, style: ParsingStyle) -> &mut Options
pub fn parsing_style(&mut self, style: ParsingStyle) -> &mut Options
Set the parsing style.
Sourcepub fn long_only(&mut self, long_only: bool) -> &mut Options
pub fn long_only(&mut self, long_only: bool) -> &mut Options
Set or clear “long options only” mode.
In “long options only” mode, short options cannot be clustered together, and long options can be given with either a single “-” or the customary “–”. This mode also changes the meaning of “-a=b”; in the ordinary mode this will parse a short option “-a” with argument “=b”; whereas in long-options-only mode the argument will be simply “b”.
Sourcepub fn opt(
&mut self,
short_name: &str,
long_name: &str,
desc: &str,
hint: &str,
hasarg: HasArg,
occur: Occur,
) -> &mut Options
pub fn opt( &mut self, short_name: &str, long_name: &str, desc: &str, hint: &str, hasarg: HasArg, occur: Occur, ) -> &mut Options
Create a generic option group, stating all parameters explicitly.
Sourcepub fn optflag(
&mut self,
short_name: &str,
long_name: &str,
desc: &str,
) -> &mut Options
pub fn optflag( &mut self, short_name: &str, long_name: &str, desc: &str, ) -> &mut Options
Create a long option that is optional and does not take an argument.
short_name
- e.g."h"
for a-h
option, or""
for nonelong_name
- e.g."help"
for a--help
option, or""
for nonedesc
- Description for usage help
§Example
let mut opts = Options::new();
opts.optflag("h", "help", "help flag");
let matches = opts.parse(&["-h"]).unwrap();
assert!(matches.opt_present("h"));
Sourcepub fn optflagmulti(
&mut self,
short_name: &str,
long_name: &str,
desc: &str,
) -> &mut Options
pub fn optflagmulti( &mut self, short_name: &str, long_name: &str, desc: &str, ) -> &mut Options
Create a long option that can occur more than once and does not take an argument.
short_name
- e.g."h"
for a-h
option, or""
for nonelong_name
- e.g."help"
for a--help
option, or""
for nonedesc
- Description for usage help
§Example
let mut opts = Options::new();
opts.optflagmulti("v", "verbose", "verbosity flag");
let matches = opts.parse(&["-v", "--verbose"]).unwrap();
assert_eq!(2, matches.opt_count("v"));
Sourcepub fn optflagopt(
&mut self,
short_name: &str,
long_name: &str,
desc: &str,
hint: &str,
) -> &mut Options
pub fn optflagopt( &mut self, short_name: &str, long_name: &str, desc: &str, hint: &str, ) -> &mut Options
Create a long option that is optional and takes an optional argument.
short_name
- e.g."h"
for a-h
option, or""
for nonelong_name
- e.g."help"
for a--help
option, or""
for nonedesc
- Description for usage helphint
- Hint that is used in place of the argument in the usage help, e.g."FILE"
for a-o FILE
option
§Example
let mut opts = Options::new();
opts.optflagopt("t", "text", "flag with optional argument", "TEXT");
let matches = opts.parse(&["--text"]).unwrap();
assert_eq!(None, matches.opt_str("text"));
let matches = opts.parse(&["--text=foo"]).unwrap();
assert_eq!(Some("foo".to_owned()), matches.opt_str("text"));
Sourcepub fn optmulti(
&mut self,
short_name: &str,
long_name: &str,
desc: &str,
hint: &str,
) -> &mut Options
pub fn optmulti( &mut self, short_name: &str, long_name: &str, desc: &str, hint: &str, ) -> &mut Options
Create a long option that is optional, takes an argument, and may occur multiple times.
short_name
- e.g."h"
for a-h
option, or""
for nonelong_name
- e.g."help"
for a--help
option, or""
for nonedesc
- Description for usage helphint
- Hint that is used in place of the argument in the usage help, e.g."FILE"
for a-o FILE
option
§Example
let mut opts = Options::new();
opts.optmulti("t", "text", "text option", "TEXT");
let matches = opts.parse(&["-t", "foo", "--text=bar"]).unwrap();
let values = matches.opt_strs("t");
assert_eq!(2, values.len());
assert_eq!("foo", values[0]);
assert_eq!("bar", values[1]);
Sourcepub fn optopt(
&mut self,
short_name: &str,
long_name: &str,
desc: &str,
hint: &str,
) -> &mut Options
pub fn optopt( &mut self, short_name: &str, long_name: &str, desc: &str, hint: &str, ) -> &mut Options
Create a long option that is optional and takes an argument.
short_name
- e.g."h"
for a-h
option, or""
for nonelong_name
- e.g."help"
for a--help
option, or""
for nonedesc
- Description for usage helphint
- Hint that is used in place of the argument in the usage help, e.g."FILE"
for a-o FILE
option
§Example
let mut opts = Options::new();
opts.optopt("o", "optional", "optional text option", "TEXT");
let matches = opts.parse(&["arg1"]).unwrap();
assert_eq!(None, matches.opt_str("optional"));
let matches = opts.parse(&["--optional", "foo", "arg1"]).unwrap();
assert_eq!(Some("foo".to_owned()), matches.opt_str("optional"));
Sourcepub fn reqopt(
&mut self,
short_name: &str,
long_name: &str,
desc: &str,
hint: &str,
) -> &mut Options
pub fn reqopt( &mut self, short_name: &str, long_name: &str, desc: &str, hint: &str, ) -> &mut Options
Create a long option that is required and takes an argument.
short_name
- e.g."h"
for a-h
option, or""
for nonelong_name
- e.g."help"
for a--help
option, or""
for nonedesc
- Description for usage helphint
- Hint that is used in place of the argument in the usage help, e.g."FILE"
for a-o FILE
option
§Example
let mut opts = Options::new();
opts.optopt("o", "optional", "optional text option", "TEXT");
opts.reqopt("m", "mandatory", "madatory text option", "TEXT");
let result = opts.parse(&["--mandatory", "foo"]);
assert!(result.is_ok());
let result = opts.parse(&["--optional", "foo"]);
assert!(result.is_err());
assert_eq!(Fail::OptionMissing("mandatory".to_owned()), result.unwrap_err());
Sourcepub fn parse<C>(&self, args: C) -> Result<Matches, Fail>
pub fn parse<C>(&self, args: C) -> Result<Matches, Fail>
Parse command line arguments according to the provided options.
On success returns Ok(Matches)
. Use methods such as opt_present
opt_str
, etc. to interrogate results.
§Panics
Returns Err(Fail)
on failure: use the Debug
implementation of Fail
to display information about it.
Sourcepub fn short_usage(&self, program_name: &str) -> String
pub fn short_usage(&self, program_name: &str) -> String
Derive a short one-line usage summary from a set of long options.
Trait Implementations§
impl Eq for Options
impl StructuralPartialEq for Options
Auto Trait Implementations§
impl Freeze for Options
impl RefUnwindSafe for Options
impl Send for Options
impl Sync for Options
impl Unpin for Options
impl UnwindSafe for Options
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self
from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self
is actually part of its subset T
(and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset
but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self
to the equivalent element of its superset.