#cli #structopt #clap #derive

structopt-toml-derive

A derive crate of structopt-toml

16 releases

0.5.0 Jul 27, 2021
0.4.5 May 6, 2020
0.4.4 Apr 30, 2020
0.4.2 Mar 12, 2020
0.1.2 Mar 19, 2018

#141 in Command-line interface

Download history 1599/week @ 2021-07-03 835/week @ 2021-07-10 1012/week @ 2021-07-17 1282/week @ 2021-07-24 1170/week @ 2021-07-31 1268/week @ 2021-08-07 1039/week @ 2021-08-14 1487/week @ 2021-08-21 1096/week @ 2021-08-28 770/week @ 2021-09-04 801/week @ 2021-09-11 933/week @ 2021-09-18 1115/week @ 2021-09-25 951/week @ 2021-10-02 1355/week @ 2021-10-09 1213/week @ 2021-10-16

6,645 downloads per month
Used in 3 crates (via structopt-toml)

MIT/Apache

8KB
162 lines

structopt-toml

An default value loader from TOML for structopt. It combinates with structopt.

Actions Status Crates.io Docs.rs codecov

Usage

This crate must be used with serde, serde_derive, structopt, and toml explicitly.

[dependencies]
serde          = "1.0.104"
serde_derive   = "1.0.104"
structopt      = "0.3.11"
structopt-toml = "0.5.0"
toml           = "0.5.6"

Example

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.

use serde_derive::Deserialize;
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 is below.

$ ./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

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Dependencies

~305–730KB
~18K SLoC

6d`