functional update

* clap: json input update
* envy: input variables
* main.rs: functions call (logic)

Signed-off-by: Ralf Zerres <ralf.zerres@networkx.de>
This commit is contained in:
2019-11-03 06:00:05 +01:00
parent 7367d1fffa
commit f391a8f278
4 changed files with 131 additions and 12 deletions

4
.env Normal file
View File

@@ -0,0 +1,4 @@
TEST_LANG=en
LANG=en
RUST_LOG=debug
#RUST_LOG=advotracker=trace

View File

@@ -1,15 +1,58 @@
{
"err.lang.not_found": {
"de_DE.UTF-8": "Konnte Sprachkode nicht auslesen",
"de": "Konnte Sprachkode nicht auslesen",
"en": "Couldn't read LANG"
},
"err.user.not_found": {
"fr": "Utilisateur introuvable: $email, $id",
"de-DE.UTF-8": "Anwender nicht gefunden: $email, $id",
"de": "Anwender nicht gefunden: $email, $id",
"en": "User not found: $email, $id"
},
"main.start": {
"de-DE.UTF-8": "Programmlogik starten",
"de": "Programmlogik starten",
"en": "Starting program logic"
},
"parse.arguments": {
"de_DE.UTF-8": "Programmargumente prüfen",
"de": "Programmargumente prüfen",
"en": "Parsing arguments"
},
"parse.environment": {
"de_DE.UTF-8": "Umgebungsvariablen prüfen",
"de": "Umgebungsvariablen prüfen",
"en": "Parsing environment"
},
"config.name": {
"de_DE.UTF-8": "Konfigurationswert für",
"de": "Konfigurationswert für",
"en": "Config Value for"
},
"config.name.lang": {
"de_DE.UTF-8": "Sprach-Code",
"de": "Sprach-Code",
"en": "Language code"
},
"config.name.verbositylevel": {
"de_DE.UTF-8": "Ausgabe-Ebene",
"de": "Ausgabe-Ebene",
"en": "verbosity level"
},
"config.name.environment": {
"de_DE.UTF-8": "Umgebungsvariablen",
"de": "Umgebungsvariablen",
"en": "environment"
},
"config.name.configfile": {
"de_DE.UTF-8": "Konfigurations-Datei",
"de": "Konfigurations-Datei",
"en": "config file"
},
"config.name.dbdriver": {
"de_DE.UTF-8": "Datenbank-Treiber",
"de": "Datenbank-Treiber",
"en": "database driver"
}
}

View File

@@ -25,11 +25,17 @@ args:
multiple: true
help: Sets the level of verbosity
subcommands:
- config:
about: configure the program environment
version: "0.1.0"
author: Ralf Zerres <ralf.zerres@networkx.de>
value_name: "FILE"
default_value: advotracker.conf
- test:
about: controls testing features
version: "0.1"
about: run testing features
version: "0.1.0"
author: Ralf Zerres <ralf.zerres@networkx.de>
args:
- debug:
- debug:
short: d
help: print debug information
help: print debug information

View File

@@ -21,17 +21,48 @@ struct Environment {
test_lang: String,
}
}
/*
struct Args {
my_conifg: String,
verbose: String,
}
*/
#[instrument]
fn run_subcommand(matches: &ArgMatches) -> Result<(), String> {
info!("inside run_subcommand");
match matches.subcommand() {
("config", Some(cmd)) => run_config(cmd),
("test", Some(cmd)) => run_test(cmd),
_ => Ok(()),
}
}
fn run_config(matches: &ArgMatches) -> Result<(), String> {
info!("inside run_config");
let _input = matches.value_of("FILE").unwrap();
Ok(())
}
fn run_test(matches: &ArgMatches) -> Result<(), String> {
info!("inside run_test");
// You can handle information about subcommands by requesting their matches by name
// (as below), requesting just the name used, or both at the same time
if let Some(matches) = matches.subcommand_matches("test") {
if matches.is_present("debug") {
println!("Printing debug info...");
println!("test: Printing debug info...");
} else {
println!("Printing normally...");
println!("test: Printing normally...");
}
}
Ok(())
}
//#[clap::main]
//#[runtime::main]
//[context_attribute::context]
//#[throw]
//fn main(args: Args) throw {
fn main() {
//initialize tracing eco-system
use tracing_subscriber::fmt;
@@ -65,8 +96,43 @@ fn main() {
let res = t!("parse.arguments", lang);
info!(target: "advotracker_event", "{}", res);
let yaml = clap::load_yaml!("cli.yml");
let matches = clap::App::from_yaml(yaml)
.name(clap::crate_name!())
.version(clap::crate_version!())
.author(clap::crate_authors!())
.about(clap::crate_description!())
.get_matches();
// Starting the program logic
let res = t!("main.start", lang);
println!("{}", &res);
// Gets the option value if supplied by user, otherwise set defaults
let config = matches.value_of("config").unwrap_or("default.conf");
let dbdriver = matches.value_of("dbdriver").unwrap_or("sqlite3");
let verbose = matches.occurrences_of("verbose");
if verbose > 0 {
let res_name = t!("config.name.configfile", lang);
println!("{}: {}", res_name, config);
let res_name = t!("config.name.dbdriver", lang);
println!("{}: {}", res_name, dbdriver);
let res_name = t!("config.name.verbositylevel", lang);
println!("{}: {}", res_name, matches.occurrences_of("verbose"));
}
if verbose > 1 {
for (key, value) in env::vars() {
println!("{}={}", key, value);
}
println!("\n");
}
// handle subcommands
if let Err(e) = run_subcommand(&matches) {
println!("Subcommand error: {}", e);
process::exit(1);
}
// Starting the program logic
let res = t!("main.start", lang);
println!("{}", &res);
});
}