pub struct getopt {
pub options: HashMap<char, String>,
pub arguments: Vec<String>,
pub option_has_arg: HashMap<char, bool>,
}
Expand description
Parsed command line options.
Created by new
function. Structure contains isolated command line
arguments and collected options with their optional values.
Structure can contain options which are not listed in optstring
passed to new
function. For strict parse mode pass this
structure to validate
function.
Fields§
§options: HashMap<char, String>
Map of command line options and their optional values extracted from command line arguments.
If an option does not have a value, an empty string “” is stored.
arguments: Vec<String>
Isolated command line arguments without options.
option_has_arg: HashMap<char, bool>
Map indicating whether an option has a required argument.
This map contains all recognized options. Inclusion of an option in this map does not mean that the option must always be present or supplied as a command line argument.
Implementations§
Source§impl getopt
impl getopt
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Return number of command line arguments.
Its convience shortcut for getopt.arguments.len()
§Example
use std::env::args;
use getopt3::hideBin;
let getopt_rc = getopt3::new(hideBin(args()), "ab:c");
if let Ok(g) = getopt_rc {
println!("Number of command line arguments is {}", g.len());
};
Sourcepub fn iter(&self) -> Iter<'_, String>
pub fn iter(&self) -> Iter<'_, String>
Returns Iterator over command line arguments.
§Example
use std::env::args;
use getopt3::hideBin;
let getopt_rc = getopt3::new(hideBin(args()), "abc");
if let Ok(my_getopt) = getopt_rc {
for arg in my_getopt.iter() {
println!("Argument: {}", arg);
}
}
Sourcepub fn get(&self, option: char) -> Option<&String>
pub fn get(&self, option: char) -> Option<&String>
Return command line option value.
Its convience shortcut for getopt.options.get()
§Return value
- If option were supplied on command line returned value is
Some
. - If option doesn’t have argument or argument is
missing, reference to empty
String
is returned. - If option were not supplied by user returned value is
None
.
§Example
use std::env::args;
use getopt3::hideBin;
let getopt_rc = getopt3::new(hideBin(args()), "ab:c");
if let Ok(my_getopt) = getopt_rc {
if let Some(b_value) = my_getopt.get('b') {
println!("-b argument is: {}", b_value);
}
}