mirror of
https://framagit.org/veretcle/scootaloo.git
synced 2025-07-21 09:31:19 +02:00
style: fmt & clippy processed
This commit is contained in:
112
src/main.rs
112
src/main.rs
@@ -1,70 +1,91 @@
|
||||
use scootaloo::*;
|
||||
use clap::{App, Arg, SubCommand};
|
||||
use log::{LevelFilter, error};
|
||||
use log::{error, LevelFilter};
|
||||
use scootaloo::*;
|
||||
use simple_logger::SimpleLogger;
|
||||
use std::str::FromStr;
|
||||
|
||||
const DEFAULT_CONFIG_PATH: &'static str = "/usr/local/etc/scootaloo.toml";
|
||||
const DEFAULT_CONFIG_PATH: &str = "/usr/local/etc/scootaloo.toml";
|
||||
|
||||
fn main() {
|
||||
let matches = App::new(env!("CARGO_PKG_NAME"))
|
||||
.version(env!("CARGO_PKG_VERSION"))
|
||||
.about("A Twitter to Mastodon bot")
|
||||
.arg(Arg::with_name("config")
|
||||
.short("c")
|
||||
.long("config")
|
||||
.value_name("CONFIG_FILE")
|
||||
.help(&format!("TOML config file for scootaloo (default {})", DEFAULT_CONFIG_PATH))
|
||||
.takes_value(true)
|
||||
.display_order(1))
|
||||
.arg(Arg::with_name("log_level")
|
||||
.short("l")
|
||||
.long("loglevel")
|
||||
.value_name("LOGLEVEL")
|
||||
.help("Log level. Valid values are: Off, Warn, Error, Info, Debug")
|
||||
.takes_value(true)
|
||||
.display_order(2))
|
||||
.subcommand(SubCommand::with_name("register")
|
||||
.version(env!("CARGO_PKG_VERSION"))
|
||||
.about("Command to register to a Mastodon Instance")
|
||||
.arg(Arg::with_name("host")
|
||||
.short("H")
|
||||
.long("host")
|
||||
.value_name("HOST")
|
||||
.help("Base URL of the Mastodon instance to register to (no default)")
|
||||
.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(&format!("TOML config file for scootaloo (default {})", DEFAULT_CONFIG_PATH))
|
||||
.takes_value(true)
|
||||
.display_order(1)))
|
||||
.get_matches();
|
||||
.version(env!("CARGO_PKG_VERSION"))
|
||||
.about("A Twitter to Mastodon bot")
|
||||
.arg(
|
||||
Arg::with_name("config")
|
||||
.short("c")
|
||||
.long("config")
|
||||
.value_name("CONFIG_FILE")
|
||||
.help(&format!(
|
||||
"TOML config file for scootaloo (default {})",
|
||||
DEFAULT_CONFIG_PATH
|
||||
))
|
||||
.takes_value(true)
|
||||
.display_order(1),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("log_level")
|
||||
.short("l")
|
||||
.long("loglevel")
|
||||
.value_name("LOGLEVEL")
|
||||
.help("Log level. Valid values are: Off, Warn, Error, Info, Debug")
|
||||
.takes_value(true)
|
||||
.display_order(2),
|
||||
)
|
||||
.subcommand(
|
||||
SubCommand::with_name("register")
|
||||
.version(env!("CARGO_PKG_VERSION"))
|
||||
.about("Command to register to a Mastodon Instance")
|
||||
.arg(
|
||||
Arg::with_name("host")
|
||||
.short("H")
|
||||
.long("host")
|
||||
.value_name("HOST")
|
||||
.help("Base URL of the Mastodon instance to register to (no default)")
|
||||
.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(&format!(
|
||||
"TOML config file for scootaloo (default {})",
|
||||
DEFAULT_CONFIG_PATH
|
||||
))
|
||||
.takes_value(true)
|
||||
.display_order(1),
|
||||
),
|
||||
)
|
||||
.get_matches();
|
||||
|
||||
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.scootaloo.db_path).unwrap();
|
||||
return;
|
||||
},
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
|
||||
if matches.is_present("log_level") {
|
||||
match LevelFilter::from_str(matches.value_of("log_level").unwrap()) {
|
||||
Ok(level) => { SimpleLogger::new().with_level(level).init().unwrap()},
|
||||
Ok(level) => SimpleLogger::new().with_level(level).init().unwrap(),
|
||||
Err(e) => {
|
||||
SimpleLogger::new().with_level(LevelFilter::Error).init().unwrap();
|
||||
SimpleLogger::new()
|
||||
.with_level(LevelFilter::Error)
|
||||
.init()
|
||||
.unwrap();
|
||||
error!("Unknown log level filter: {}", e);
|
||||
}
|
||||
};
|
||||
@@ -74,4 +95,3 @@ fn main() {
|
||||
|
||||
run(config);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user