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:
25
src/main.rs
25
src/main.rs
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user