Files
scootaloo/src/main.rs

64 lines
2.6 KiB
Rust
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// self
use scootaloo::*;
// clap
use clap::{App, Arg, SubCommand};
// log
use log::{LevelFilter, error};
use simple_logger::SimpleLogger;
// std
use std::str::FromStr;
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("TOML config file for scootaloo (default /usr/local/etc/scootaloo.toml)")
.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)))
.get_matches();
if let Some(matches) = matches.subcommand_matches("register") {
register(matches.value_of("host").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()},
Err(e) => {
SimpleLogger::new().with_level(LevelFilter::Error).init().unwrap();
error!("Unknown log level filter: {}", e);
}
};
}
let config = parse_toml(matches.value_of("config").unwrap_or("/usr/local/etc/scootaloo.toml"));
run(config);
}