mirror of
https://framagit.org/veretcle/scootaloo.git
synced 2025-07-21 09:31:19 +02:00
refactor: make everything a little more modular
This commit is contained in:
29
src/main.rs
29
src/main.rs
@@ -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);
|
||||
}
|
||||
|
Reference in New Issue
Block a user