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

@@ -1,8 +1,8 @@
name: AdvoTracker
version: "0.0.1"
author: Ralf Zerres <ralf.zerres@networkx.de>
#about: AdvoTracker unterstützt Anwälte bei der Erfassung relevanter Mandatsdaten in einer Online-Beratung
about: AdvoTracker supports lawyers to capture relevant data encountered during an online legal advice
name: myapp
version: "1.0"
author: Networkx GmbH <info@networkx.de>
about: capture relevant data encountered during an online legal advice
after_help: in Zusammenarbeit mit HIEDEMANN Rechtsanwälte
args:
- config:
short: c
@@ -10,8 +10,18 @@ args:
value_name: FILE
help: Sets a custom config file
takes_value: true
- dbdriver:
short: D
long: dbdriver
help: Driver used to connect to database
possible_values:
- mysql
- postgres
- sqlite
takes_value: true
- verbose:
short: v
long: verbose
multiple: true
help: Sets the level of verbosity
subcommands:

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);
}