pub struct Options { /* private fields */ }Expand description
The Options is a collection of AnpOption and OptionGroup.
§Examples
Basic usage
use anpcli::{AnpOption, Options};
let mut options = Options::new();
options.add_option0("v", false, "print verbosely").unwrap();
options.add_option1("output", "output filename").unwrap();
options.add_option2("i", "input", true, "input filename").unwrap();
options.add_option(AnpOption::builder()
.long_option("algorithm")
.number_of_args(1)
.desc("the algorithm used to process file")
.build().unwrap());Set default values. Note that if the default values have a key
not found in the actual options, the parser will result in [ParseErr].
use std::collections::HashMap;
use anpcli::Options;
let mut defaults = HashMap::new();
defaults.insert("target".to_string(), "binary".to_string());
let mut options = Options::new();
options.set_defaults(defaults);
options.add_option0("target", true, "the target output format").unwrap();Implementations§
Source§impl Options
impl Options
Sourcepub fn has_defaults(&self) -> bool
pub fn has_defaults(&self) -> bool
Check if the Options has any default value.
Sourcepub fn set_defaults(&mut self, defaults: HashMap<String, String>)
pub fn set_defaults(&mut self, defaults: HashMap<String, String>)
Set default values for options.
Sourcepub fn get_defaults(&self) -> Option<&HashMap<String, String>>
pub fn get_defaults(&self) -> Option<&HashMap<String, String>>
Get the immutable reference of the default values if exists.
Sourcepub fn add_option(&mut self, option: AnpOption)
pub fn add_option(&mut self, option: AnpOption)
Add an AnpOption to the collection.
Also see Self::add_option0, Self::add_option1, Self::add_option2,
Self::add_required_option
Sourcepub fn add_option0(
&mut self,
opt: &str,
has_arg: bool,
description: &str,
) -> Result<(), OptionErr>
pub fn add_option0( &mut self, opt: &str, has_arg: bool, description: &str, ) -> Result<(), OptionErr>
A convenient way to add AnpOption to the collection.
Also see Self::add_option, Self::add_option1, Self::add_option2,
Self::add_required_option
Sourcepub fn add_option1(
&mut self,
opt: &str,
description: &str,
) -> Result<(), OptionErr>
pub fn add_option1( &mut self, opt: &str, description: &str, ) -> Result<(), OptionErr>
A convenient way to add AnpOption to the collection.
Also see Self::add_option, Self::add_option0, Self::add_option2,
Self::add_required_option
Sourcepub fn add_option2(
&mut self,
opt: &str,
long_opt: &str,
has_arg: bool,
description: &str,
) -> Result<(), OptionErr>
pub fn add_option2( &mut self, opt: &str, long_opt: &str, has_arg: bool, description: &str, ) -> Result<(), OptionErr>
A convenient way to add AnpOption to the collection.
Also see Self::add_option, Self::add_option0, Self::add_option1,
Self::add_required_option
Sourcepub fn add_option_group(&mut self, group: OptionGroup)
pub fn add_option_group(&mut self, group: OptionGroup)
Add an option group to the collection.
Sourcepub fn add_required_option(
&mut self,
opt: &str,
long_opt: &str,
has_arg: bool,
description: &str,
) -> Result<(), OptionErr>
pub fn add_required_option( &mut self, opt: &str, long_opt: &str, has_arg: bool, description: &str, ) -> Result<(), OptionErr>
A convenient way to add required AnpOption to the collection.
Also see Self::add_option, Self::add_option0, Self::add_option1,
Self::add_option2
Sourcepub fn get_matching_options(&self, opt: &str) -> Vec<String>
pub fn get_matching_options(&self, opt: &str) -> Vec<String>
For internal usage.