Crate structopt_toml [] [src]

structopt-toml is an default value loader from TOML for structopt.

Examples

The following example show a quick example of structopt-toml.

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.

#[macro_use]
extern crate serde_derive;
#[macro_use]
extern crate structopt;
#[macro_use]
extern crate structopt_toml;
extern crate toml;
 
use structopt::StructOpt;
use structopt_toml::StructOptToml;
 
#[derive(Debug, Deserialize, StructOpt, StructOptToml)]
#[serde(default)]
struct Opt {
    #[structopt(default_value = "0", short = "a")] a: i32,
    #[structopt(default_value = "0", short = "b")] b: i32,
}
 
fn main() {
    let toml_str = r#"
        a = 10
    "#;
    let opt = Opt::from_args_with_toml(toml_str).expect("toml parse failed");
    println!("a:{}", opt.a);
    println!("b:{}", opt.b);
}

The execution result of the above example is below.

This example is not tested
$ ./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

Modules

clap

Re-export of clap

serde

Re-export of serde

structopt

Re-export of structopt

Structs

Error

The Error type.

Enums

ErrorKind

The kind of an error.

Traits

ResultExt

Additional methods for Result, for easy interaction with this crate.

StructOptToml

Type Definitions

Result

Convenient wrapper around std::Result.