Struct getopts::Options

source ·
pub struct Options {
    pub(crate) grps: Vec<OptGroup>,
    pub(crate) parsing_style: ParsingStyle,
    pub(crate) long_only: bool,
}
Expand description

A description of the options that a program can handle.

Fields§

§grps: Vec<OptGroup>§parsing_style: ParsingStyle§long_only: bool

Implementations§

source§

impl Options

source

pub fn new() -> Options

Create a blank set of options.

source

pub fn parsing_style(&mut self, style: ParsingStyle) -> &mut Options

Set the parsing style.

source

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”.

source

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.

source

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 none
  • long_name - e.g. "help" for a --help option, or "" for none
  • desc - Description for usage help
source

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 none
  • long_name - e.g. "help" for a --help option, or "" for none
  • desc - Description for usage help
source

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 none
  • long_name - e.g. "help" for a --help option, or "" for none
  • desc - Description for usage help
  • hint - Hint that is used in place of the argument in the usage help, e.g. "FILE" for a -o FILE option
source

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 none
  • long_name - e.g. "help" for a --help option, or "" for none
  • desc - Description for usage help
  • hint - Hint that is used in place of the argument in the usage help, e.g. "FILE" for a -o FILE option
source

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 none
  • long_name - e.g. "help" for a --help option, or "" for none
  • desc - Description for usage help
  • hint - Hint that is used in place of the argument in the usage help, e.g. "FILE" for a -o FILE option
source

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 none
  • long_name - e.g. "help" for a --help option, or "" for none
  • desc - Description for usage help
  • hint - Hint that is used in place of the argument in the usage help, e.g. "FILE" for a -o FILE option
source

pub fn parse<C: IntoIterator>(&self, args: C) -> Resultwhere C::Item: AsRef<OsStr>,

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.

source

pub fn short_usage(&self, program_name: &str) -> String

Derive a short one-line usage summary from a set of long options.

source

pub fn usage(&self, brief: &str) -> String

Derive a formatted message from a set of options.

source

pub fn usage_with_format<F: FnMut(&mut dyn Iterator<Item = String>) -> String>( &self, formatter: F ) -> String

Derive a custom formatted message from a set of options. The formatted options provided to a closure as an iterator.

source

pub(crate) fn usage_items<'a>(&'a self) -> Box<dyn Iterator<Item = String> + 'a>

Derive usage items from a set of options.

Trait Implementations§

source§

impl Default for Options

source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.