-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add support of clap derive feature #15
Signed-off-by: Benjamin Coenen <[email protected]>
- Loading branch information
Showing
7 changed files
with
54 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,2 @@ | ||
[workspace] | ||
members = ["twelf", "config-derive"] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,4 +24,4 @@ fn main() { | |
.unwrap(); | ||
|
||
println!("config - {:?}", config); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#![allow(dead_code)] | ||
|
||
use clap_rs as clap; | ||
use clap::{Parser, Subcommand, CommandFactory}; | ||
use twelf::{config, Layer}; | ||
|
||
#[config] | ||
#[derive(Parser, Debug)] | ||
#[clap(author, version, about, long_about = None)] | ||
struct Config { | ||
#[clap( | ||
long, | ||
help = "Documentation inside clap, to specifiy db_host", | ||
)] | ||
db_host: String, | ||
#[clap( | ||
long, | ||
short, | ||
help = "The number of threads", | ||
)] | ||
#[clap(required = false)] | ||
threads: usize, | ||
#[clap( | ||
long, | ||
short, | ||
help = "Put in verbose mode", | ||
)] | ||
verbose: bool, | ||
} | ||
|
||
// execute `cargo run --example clap_derive -- --help` to display help and documentation | ||
// execute `cargo run --example clap_derive -- --db-host localhost --threads 5` to set configuration | ||
fn main() { | ||
let matches = Config::command().ignore_errors(true).get_matches(); | ||
let config = | ||
Config::with_layers(&[Layer::Env(Some(String::from("APP_"))), Layer::Clap(matches)]) | ||
.unwrap(); | ||
|
||
println!("config - {:?}", config); | ||
} |