Crates.io | merge-cfg |
lib.rs | merge-cfg |
version | 0.1.1 |
source | src |
created_at | 2023-10-26 08:54:21.173322 |
updated_at | 2023-11-06 09:34:07.477127 |
description | Merge or cover config based on priorities. |
homepage | |
repository | |
max_upload_size | |
id | 1014247 |
size | 7,931 |
Merge or cover config based on priorities.
You can get your configuration from config file in any way at first. Then derive MergeCfg
to merge your configuration from command line arguments.
use merge_cfg::MergeCfg;
#[derive(Debug, MergeCfg)]
struct Config {
id: u64,
name: String,
scores: Vec<i32>,
}
fn main() {
let mut cfg = Config {
id: 1,
name: "abc".to_string(),
scores: vec![-1],
};
cfg.merge_cfg();
println!("{:?}", cfg);
}
Command line arguments format: {field}={value}
, field name should be the same with what you defined in your structure:
$ cargo run
Config { id: 1, name: "abc", scores: [-1] }
$ cargo run id=2
Config { id: 2, name: "abc", scores: [-1] }
$ cargo run name=xyz
Config { id: 1, name: "xyz", scores: [-1] }
$ cargo run scores=100 scores=-1000
Config { id: 1, name: "abc", scores: [100, -1000] }
$ cargo run id=2 name=xyz scores=100
Config { id: 2, name: "xyz", scores: [100] }
{field}={value}
-h --{field} {value}