enhance commandline parsing

* prefere settings in Cargo.toml
* introduce option dbdriver

Signed-off-by: Ralf Zerres <ralf.zerres@networkx.de>
This commit is contained in:
2019-10-31 17:46:38 +01:00
parent 0a9fdbab2a
commit 47cd81a4e1
2 changed files with 39 additions and 6 deletions

View File

@@ -14,8 +14,31 @@ fn main() {
println!("{}", &res);
let yaml = load_yaml!("cli.yml");
let _matches = App::from_yaml(yaml).get_matches();
let matches = App::from_yaml(yaml)
.name(crate_name!())
.version(crate_version!())
.author(crate_authors!())
.about(crate_description!())
.get_matches();
// Gets a options value if supplied by user. otherwise set defaults
let config = matches.value_of("config").unwrap_or("default.conf");
println!("Value for config: {}", config);
let dbdriver = matches.value_of("dbdriver").unwrap_or("sqlite3");
println!("Value for database driver: {}", dbdriver);
// Vary the output based on how many times the user used the "verbose" flag
// (i.e. ' -v -v -v' or 'myprog -vvv' vs 'myprog -v'
match matches.occurrences_of("v") {
0 => println!("No verbose info"),
1 => println!("Some verbose info"),
2 => println!("Tons of verbose info"),
3 | _ => println!("Don't be crazy"),
}
// Starting the program logic
let res = t!("main.start", lang);
println!("{}", &res);
}