You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Then, overriding config file attributes with environment variable or command line.
I'm not sure exactly how to represent this in Rust, but something like:
#[derive(StructOpt,Debug)]#[structopt(name = "example", about = "An example of StructOpt usage.")]structOpt{/// The config file#[structopt(short = "c", long = "config", help = "Config file")]config_file:Option<Config>,#[structopt(flatten, required_unless = "config_file")options:Option<Config>,}#[derive(StructOpt,Debug)]structConfig{/// A flag, true if used in the command line.#[structopt(short = "d", long = "debug", help = "Activate debug mode")]debug:bool,/// An argument of type float, with a default value.#[structopt(short = "s", long = "speed", help = "Set speed", default_value = "42")]speed:f64,/// Needed parameter, the first on the command line.#[structopt(help = "Input file")]input:String,/// An optional parameter, will be `None` if not present on the/// command line.#[structopt(help = "Output file, stdout if not present")]output:Option<String>,/// An optional parameter with optional value, will be `None` if/// not present on the command line, will be `Some(None)` if no/// argument is provided (i.e. `--log`) and will be/// `Some(Some(String))` if argument is provided (e.g. `--log/// log.txt`).#[structopt( long = "log", help = "Log file, stdout if no file, no logging if not present")]log:Option<Option<String>>,/// An optional list of values, will be `None` if not present on/// the command line, will be `Some(vec![])` if no argument is/// provided (i.e. `--optv`) and will be `Some(Some(String))` if/// argument list is provided (e.g. `--optv a b c`).#[structopt(long = "optv")]optv:Option<Vec<String>>,}
The text was updated successfully, but these errors were encountered:
if -f or --file is given on the command line, it is used, else if the environment variable FILE is setted, it is used, else the default value "foo" is used.
Wednesday Jun 05, 2019 at 04:46 GMT
Originally opened as TeXitoi/structopt#197
A few common use-cases:
Then, overriding config file attributes with environment variable or command line.
I'm not sure exactly how to represent this in Rust, but something like:
The text was updated successfully, but these errors were encountered: