pub struct Config { /* private fields */ }Expand description
Specifies a configuration of parsed arguments
Each option which was given as a spec can be accessed by option(name)
This returns a Option<Vec
Implementations§
Source§impl Config
Parses and generates configuration from supplied arguments and option specifications
Can also generate usage strings
impl Config
Parses and generates configuration from supplied arguments and option specifications Can also generate usage strings
Sourcepub fn new_env(specs: &[OptionSpec]) -> Result<Config, String>
pub fn new_env(specs: &[OptionSpec]) -> Result<Config, String>
Same as Config::new but uses the arguments passed to the program (env::args)
The program path, first argument, is included in the unnamed args
Note, the spec isn’t stored with config
Sourcepub fn new(args: &[&str], specs: &[OptionSpec]) -> Result<Config, String>
pub fn new(args: &[&str], specs: &[OptionSpec]) -> Result<Config, String>
Parses config from custom supplied arguments
Specs is a list containing specifications for the available options a use can supply
Returns Err(msg) if a spec doesn’t match what is specified
The arguments before any option are specified with the (unnamed)
The values for the options can be accessed with the option(name) method
Parsing will fail if an option with policy other than Exact(0) is used twice
Note, the spec isn’t stored with config
Sourcepub fn generate_usage(
specs: &[OptionSpec],
list_required: bool,
list_unrequired: bool,
) -> String
pub fn generate_usage( specs: &[OptionSpec], list_required: bool, list_unrequired: bool, ) -> String
Generates a usage string from supplied specs