parse_args: make vektor 'viperus' explicit
* when using as a globel, this is more easy to recognize Signed-off-by: Ralf Zerres <ralf.zerres@networkx.de>
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* advotracker - Hotline tackingtool for Advocats
|
* advotracker - Hotline tackingtool for Advocats
|
||||||
*
|
|
||||||
* Copyright 2020 Ralf Zerres <ralf.zerres@networkx.de>
|
* Copyright 2020 Ralf Zerres <ralf.zerres@networkx.de>
|
||||||
* SPDX-License-Identifier: (0BSD or MIT)
|
* SPDX-License-Identifier: (0BSD or MIT)
|
||||||
*/
|
*/
|
||||||
@@ -146,12 +146,8 @@ SMR Unerledigt: 089 92529 60222")
|
|||||||
);
|
);
|
||||||
|
|
||||||
// enable caching and automatic update of environment values
|
// enable caching and automatic update of environment values
|
||||||
if cfg!(feature = "fmt-cache") {
|
v.cache(true);
|
||||||
v.cache(true);
|
v.automatic_env(true);
|
||||||
}
|
|
||||||
if cfg!(feature = "fmt-env") {
|
|
||||||
v.automatic_env(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
// load user selected call arguments
|
// load user selected call arguments
|
||||||
// -> overwrites values given via environment variables
|
// -> overwrites values given via environment variables
|
||||||
|
|||||||
@@ -15,23 +15,27 @@ use viperus::Viperus;
|
|||||||
|
|
||||||
/// Parse the commandline arguments and preset default values
|
/// Parse the commandline arguments and preset default values
|
||||||
/// Precedence: defaults -> config-file -> environment -> commandline
|
/// Precedence: defaults -> config-file -> environment -> commandline
|
||||||
pub fn parse_args(v: &mut Viperus) -> Result<(), Box<dyn std::error::Error>> {
|
pub fn parse_args(viperus: &mut Viperus) -> Result<(), Box<dyn std::error::Error>> {
|
||||||
|
if cfg!(feature = "global") {
|
||||||
|
trace!(target: "Viperus", "Viperus feature 'global' enabled.");
|
||||||
|
println!("Lasy static: 'VIPERUS' is accessible globaly");
|
||||||
|
}
|
||||||
|
|
||||||
if cfg!(feature = "fmt-clap") {
|
if cfg!(feature = "fmt-clap") {
|
||||||
trace!(target: "Viperus", "Viperus feature 'fmt-clap' enabled.");
|
trace!(target: "Viperus", "Viperus feature 'fmt-clap' enabled.");
|
||||||
println!("Using feature fmt-clap");
|
println!("Using feature fmt-clap");
|
||||||
}
|
}
|
||||||
|
|
||||||
// preset default key/value pairs (lowest priority)
|
// preset default key/value pairs (lowest priority)
|
||||||
v.add_default("config_file", String::from("csv_import.ron"));
|
viperus.add_default("config_file", String::from("csv_import.ron"));
|
||||||
v.add_default("import_file", String::from("POLLFNR_WOECHENTLICH.txt"));
|
viperus.add_default("import_file", String::from("POLLFNR_WOECHENTLICH.txt"));
|
||||||
v.add_default("export_file", String::from(""));
|
viperus.add_default("export_file", String::from(""));
|
||||||
v.add_default("test_policy_number", 123456789);
|
viperus.add_default("test_policy_number", 123456789);
|
||||||
v.add_default("to_email_address_file", String::from("Allianz RA-Hotline <smr-rahotline@allianz.de>"));
|
viperus.add_default("to_email_address_file", String::from("Allianz RA-Hotline <smr-rahotline@allianz.de>"));
|
||||||
v.add_default("from_email_address_file", String::from("Allianz-Hotline RA-Hiedemann <azhotline@hiedemann.de>"));
|
viperus.add_default("from_email_address_file", String::from("Allianz-Hotline RA-Hiedemann <azhotline@hiedemann.de>"));
|
||||||
//v.add_default("username", String::from("nctalkbot"));
|
//viperus.add_default("username", String::from("nctalkbot"));
|
||||||
//v.add_default("password", String::from("botpassword"));
|
//viperus.add_default("password", String::from("botpassword"));
|
||||||
v.add_default("verbose", 0);
|
viperus.add_default("verbose", 0);
|
||||||
|
|
||||||
|
|
||||||
// CLI arguments are defined inline
|
// CLI arguments are defined inline
|
||||||
let matches = App::new("advotracker")
|
let matches = App::new("advotracker")
|
||||||
@@ -130,13 +134,13 @@ SMR Unerledigt: 089 92529 60222")
|
|||||||
if matches.occurrences_of("verbose") > 0 {
|
if matches.occurrences_of("verbose") > 0 {
|
||||||
// clap is using i64, viperus i32
|
// clap is using i64, viperus i32
|
||||||
let n = matches.occurrences_of("verbose") as i32;
|
let n = matches.occurrences_of("verbose") as i32;
|
||||||
v.add("verbose", n);
|
viperus.add("verbose", n);
|
||||||
}
|
}
|
||||||
|
|
||||||
// preset the prefix for relevant environment variables ("ADVOTRACKER_")
|
// preset the prefix for relevant environment variables ("ADVOTRACKER_")
|
||||||
let mut env_prefix: String = crate_name!().to_uppercase();
|
let mut env_prefix: String = crate_name!().to_uppercase();
|
||||||
env_prefix.push_str("_");
|
env_prefix.push_str("_");
|
||||||
v.set_env_prefix(&env_prefix);
|
viperus.set_env_prefix(&env_prefix);
|
||||||
|
|
||||||
// respect dotenv environment (e.g for testing)
|
// respect dotenv environment (e.g for testing)
|
||||||
// -> overwrites the preset default values
|
// -> overwrites the preset default values
|
||||||
@@ -146,70 +150,66 @@ SMR Unerledigt: 089 92529 60222")
|
|||||||
);
|
);
|
||||||
|
|
||||||
// enable caching and automatic update of environment values
|
// enable caching and automatic update of environment values
|
||||||
if cfg!(feature = "fmt-cache") {
|
viperus.cache(true);
|
||||||
v.cache(true);
|
viperus.automatic_env(true);
|
||||||
}
|
|
||||||
if cfg!(feature = "fmt-env") {
|
|
||||||
v.automatic_env(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
// load user selected call arguments
|
// load user selected call arguments
|
||||||
// -> overwrites values given via environment variables
|
// -> overwrites values given via environment variables
|
||||||
v.load_clap(matches)?;
|
viperus.load_clap(matches)?;
|
||||||
|
|
||||||
// bond the clap names to camel_case rust variable names
|
// bond the clap names to camel_case rust variable names
|
||||||
v.bond_clap("configFile", "config_file");
|
viperus.bond_clap("configFile", "config_file");
|
||||||
v.bond_clap("importFile", "import_file");
|
viperus.bond_clap("importFile", "import_file");
|
||||||
v.bond_clap("exportFile", "export_file");
|
viperus.bond_clap("exportFile", "export_file");
|
||||||
v.bond_clap("toEmailAddress", "to_email_address");
|
viperus.bond_clap("toEmailAddress", "to_email_address");
|
||||||
v.bond_clap("fromEmailAddress", "from_email_address");
|
viperus.bond_clap("fromEmailAddress", "from_email_address");
|
||||||
v.bond_clap("testPolicyNumber", "test_policy_number");
|
viperus.bond_clap("testPolicyNumber", "test_policy_number");
|
||||||
//v.bond_clap("username", "username");
|
//viperus.bond_clap("username", "username");
|
||||||
//v.bond_clap("password", "password");
|
//viperus.bond_clap("password", "password");
|
||||||
v.bond_clap("verbose", "verbose");
|
viperus.bond_clap("verbose", "verbose");
|
||||||
|
|
||||||
trace!("verbose {:?}", v.get::<i32>("verbose").unwrap());
|
trace!("verbose {:?}", viperus.get::<i32>("verbose").unwrap());
|
||||||
if v.get::<i32>("verbose").unwrap() > 0 {
|
if viperus.get::<i32>("verbose").unwrap() > 0 {
|
||||||
println!(
|
println!(
|
||||||
"config_file: {:?}",
|
"config_file: {:?}",
|
||||||
v.get::<String>("config_file").unwrap_or_default()
|
viperus.get::<String>("config_file").unwrap_or_default()
|
||||||
);
|
);
|
||||||
println!(
|
println!(
|
||||||
"import_file: {:?}",
|
"import_file: {:?}",
|
||||||
v.get::<String>("import_file").unwrap_or_default()
|
viperus.get::<String>("import_file").unwrap_or_default()
|
||||||
);
|
);
|
||||||
println!(
|
println!(
|
||||||
"export_file: {:?}",
|
"export_file: {:?}",
|
||||||
v.get::<String>("export_file").unwrap_or_default()
|
viperus.get::<String>("export_file").unwrap_or_default()
|
||||||
);
|
);
|
||||||
println!(
|
println!(
|
||||||
"to_email_address: {:?}",
|
"to_email_address: {:?}",
|
||||||
v.get::<String>("to_email_address").unwrap_or_default()
|
viperus.get::<String>("to_email_address").unwrap_or_default()
|
||||||
);
|
);
|
||||||
println!(
|
println!(
|
||||||
"from_email_address: {:?}",
|
"from_email_address: {:?}",
|
||||||
v.get::<String>("from_email_address").unwrap_or_default()
|
viperus.get::<String>("from_email_address").unwrap_or_default()
|
||||||
);
|
);
|
||||||
println!(
|
println!(
|
||||||
"test_policy_number: {:?}",
|
"test_policy_number: {:?}",
|
||||||
v.get::<i32>("test_policy_number").unwrap_or_default()
|
viperus.get::<i32>("test_policy_number").unwrap_or_default()
|
||||||
);
|
);
|
||||||
// println!(
|
// println!(
|
||||||
// "username: {:?}",
|
// "username: {:?}",
|
||||||
// v.get::<String>("username").unwrap_or_default()
|
// viperus.get::<String>("username").unwrap_or_default()
|
||||||
// );
|
// );
|
||||||
// println!(
|
// println!(
|
||||||
// "password: {:?}",
|
// "password: {:?}",
|
||||||
// v.get::<String>("password").unwrap_or_default()
|
// viperus.get::<String>("password").unwrap_or_default()
|
||||||
// ); // only for testing now
|
// ); // only for testing now
|
||||||
|
|
||||||
println!(
|
println!(
|
||||||
"verbosity level: {:?}",
|
"verbosity level: {:?}",
|
||||||
v.get::<i32>("verbose").unwrap_or_default()
|
viperus.get::<i32>("verbose").unwrap_or_default()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if v.get::<i32>("verbose").unwrap() > 1 {
|
if viperus.get::<i32>("verbose").unwrap() > 1 {
|
||||||
println!("\nEnvironment:");
|
println!("\nEnvironment:");
|
||||||
for (key, value) in env::vars() {
|
for (key, value) in env::vars() {
|
||||||
println!("{}={}", key, value);
|
println!("{}={}", key, value);
|
||||||
|
|||||||
Reference in New Issue
Block a user