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:
4
.env
Normal file
4
.env
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
TEST_LANG=en
|
||||||
|
LANG=en
|
||||||
|
RUST_LOG=debug
|
||||||
|
#RUST_LOG=advotracker=trace
|
||||||
@@ -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": {
|
"err.user.not_found": {
|
||||||
"fr": "Utilisateur introuvable: $email, $id",
|
"fr": "Utilisateur introuvable: $email, $id",
|
||||||
|
"de-DE.UTF-8": "Anwender nicht gefunden: $email, $id",
|
||||||
"de": "Anwender nicht gefunden: $email, $id",
|
"de": "Anwender nicht gefunden: $email, $id",
|
||||||
"en": "User not found: $email, $id"
|
"en": "User not found: $email, $id"
|
||||||
},
|
},
|
||||||
"main.start": {
|
"main.start": {
|
||||||
|
"de-DE.UTF-8": "Programmlogik starten",
|
||||||
"de": "Programmlogik starten",
|
"de": "Programmlogik starten",
|
||||||
"en": "Starting program logic"
|
"en": "Starting program logic"
|
||||||
},
|
},
|
||||||
"parse.arguments": {
|
"parse.arguments": {
|
||||||
|
"de_DE.UTF-8": "Programmargumente prüfen",
|
||||||
"de": "Programmargumente prüfen",
|
"de": "Programmargumente prüfen",
|
||||||
"en": "Parsing arguments"
|
"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"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
10
src/cli.yml
10
src/cli.yml
@@ -25,9 +25,15 @@ args:
|
|||||||
multiple: true
|
multiple: true
|
||||||
help: Sets the level of verbosity
|
help: Sets the level of verbosity
|
||||||
subcommands:
|
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:
|
- test:
|
||||||
about: controls testing features
|
about: run testing features
|
||||||
version: "0.1"
|
version: "0.1.0"
|
||||||
author: Ralf Zerres <ralf.zerres@networkx.de>
|
author: Ralf Zerres <ralf.zerres@networkx.de>
|
||||||
args:
|
args:
|
||||||
- debug:
|
- debug:
|
||||||
|
|||||||
76
src/main.rs
76
src/main.rs
@@ -21,17 +21,48 @@ struct Environment {
|
|||||||
test_lang: String,
|
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 let Some(matches) = matches.subcommand_matches("test") {
|
||||||
if matches.is_present("debug") {
|
if matches.is_present("debug") {
|
||||||
println!("Printing debug info...");
|
println!("test: Printing debug info...");
|
||||||
} else {
|
} else {
|
||||||
println!("Printing normally...");
|
println!("test: Printing normally...");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
//#[clap::main]
|
||||||
|
//#[runtime::main]
|
||||||
|
//[context_attribute::context]
|
||||||
|
//#[throw]
|
||||||
|
//fn main(args: Args) throw {
|
||||||
fn main() {
|
fn main() {
|
||||||
//initialize tracing eco-system
|
//initialize tracing eco-system
|
||||||
use tracing_subscriber::fmt;
|
use tracing_subscriber::fmt;
|
||||||
@@ -65,8 +96,43 @@ fn main() {
|
|||||||
let res = t!("parse.arguments", lang);
|
let res = t!("parse.arguments", lang);
|
||||||
info!(target: "advotracker_event", "{}", res);
|
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();
|
||||||
|
|
||||||
|
// 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
|
// 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