refactor: make everything a little more modular

This commit is contained in:
VC
2022-04-22 13:36:02 +02:00
parent de375b9f28
commit 080218f385
11 changed files with 478 additions and 323 deletions

View File

@@ -11,6 +11,8 @@ use simple_logger::SimpleLogger;
// std
use std::str::FromStr;
const DEFAULT_CONFIG_PATH: &'static str = "/usr/local/etc/scootaloo.toml";
fn main() {
let matches = App::new(env!("CARGO_PKG_NAME"))
.version(env!("CARGO_PKG_VERSION"))
@@ -40,10 +42,29 @@ fn main() {
.takes_value(true)
.required(true)
.display_order(1)))
.subcommand(SubCommand::with_name("init")
.version(env!("CARGO_PKG_VERSION"))
.about("Command to init Scootaloo DB")
.arg(Arg::with_name("config")
.short("c")
.long("config")
.value_name("CONFIG_FILE")
.help("TOML config file for scootaloo (default /usr/local/etc/scootaloo.toml")
.takes_value(true)
.display_order(1)))
.get_matches();
if let Some(matches) = matches.subcommand_matches("register") {
register(matches.value_of("host").unwrap());
return;
match matches.subcommand() {
("register", Some(sub_m)) => {
register(sub_m.value_of("host").unwrap());
return;
},
("init", Some(sub_m)) => {
let config = parse_toml(sub_m.value_of("config").unwrap_or(DEFAULT_CONFIG_PATH));
init_db(&config).unwrap();
return;
},
_ => (),
}
if matches.is_present("log_level") {
@@ -56,7 +77,7 @@ fn main() {
};
}
let config = parse_toml(matches.value_of("config").unwrap_or("/usr/local/etc/scootaloo.toml"));
let config = parse_toml(matches.value_of("config").unwrap_or(DEFAULT_CONFIG_PATH));
run(config);
}