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:
20
src/cli.yml
20
src/cli.yml
@@ -1,8 +1,8 @@
|
|||||||
name: AdvoTracker
|
name: myapp
|
||||||
version: "0.0.1"
|
version: "1.0"
|
||||||
author: Ralf Zerres <ralf.zerres@networkx.de>
|
author: Networkx GmbH <info@networkx.de>
|
||||||
#about: AdvoTracker unterstützt Anwälte bei der Erfassung relevanter Mandatsdaten in einer Online-Beratung
|
about: capture relevant data encountered during an online legal advice
|
||||||
about: AdvoTracker supports lawyers to capture relevant data encountered during an online legal advice
|
after_help: in Zusammenarbeit mit HIEDEMANN Rechtsanwälte
|
||||||
args:
|
args:
|
||||||
- config:
|
- config:
|
||||||
short: c
|
short: c
|
||||||
@@ -10,8 +10,18 @@ args:
|
|||||||
value_name: FILE
|
value_name: FILE
|
||||||
help: Sets a custom config file
|
help: Sets a custom config file
|
||||||
takes_value: true
|
takes_value: true
|
||||||
|
- dbdriver:
|
||||||
|
short: D
|
||||||
|
long: dbdriver
|
||||||
|
help: Driver used to connect to database
|
||||||
|
possible_values:
|
||||||
|
- mysql
|
||||||
|
- postgres
|
||||||
|
- sqlite
|
||||||
|
takes_value: true
|
||||||
- verbose:
|
- verbose:
|
||||||
short: v
|
short: v
|
||||||
|
long: verbose
|
||||||
multiple: true
|
multiple: true
|
||||||
help: Sets the level of verbosity
|
help: Sets the level of verbosity
|
||||||
subcommands:
|
subcommands:
|
||||||
|
|||||||
25
src/main.rs
25
src/main.rs
@@ -14,8 +14,31 @@ fn main() {
|
|||||||
println!("{}", &res);
|
println!("{}", &res);
|
||||||
|
|
||||||
let yaml = load_yaml!("cli.yml");
|
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);
|
let res = t!("main.start", lang);
|
||||||
println!("{}", &res);
|
println!("{}", &res);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user