An default value loader from TOML for structopt. It combinates with structopt.
Cargo.toml
[dependencies]
structopt-toml = "0.1.0"
If derive(Deserialize)
, derive(StructOptToml)
and serde(default)
are added to the struct with derive(StructOpt)
, some functions like from_args_with_toml
can be used.
```rust
extern crate serde_derive;
extern crate structopt;
extern crate structopt_toml; extern crate toml;
use structopt::StructOpt; use structopt_toml::StructOptToml;
struct Opt { #[structopt(defaultvalue = "0", short = "a")] a: i32, #[structopt(defaultvalue = "0", short = "b")] b: i32, }
fn main() { let tomlstr = r#" a = 10 "#; let opt = Opt::fromargswithtoml(toml_str); println!("a:{}", opt.a); println!("b:{}", opt.b); } ```
The execution result is below.
```console $ ./example a:10 // value from TOML string b:0 // value from default_value of structopt
$ ./example -a 20 a:20 // value from command line argument b:0 ```