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:
82
src/main.rs
82
src/main.rs
@@ -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);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user