Add optional --dbpath flag (#6)

* Use common config with lower cache capacity

* Add command line argument parser

* Add optional --dbpath flag
This commit is contained in:
Dave Gallant
2020-06-22 22:54:06 -04:00
committed by GitHub
parent 94863c3c69
commit 1989b48d99
6 changed files with 101 additions and 31 deletions

View File

@@ -1,38 +1,48 @@
extern crate pretty_env_logger;
#[macro_use]
extern crate log;
extern crate clap;
extern crate crypto;
mod config;
mod db;
mod mail;
mod rfd;
use std::env;
fn help() {
println!(
"usage:\n
rfd-notify <config-toml>
Specify the filepath of the config."
);
}
use clap::{App, Arg};
fn main() {
pretty_env_logger::init();
let args: Vec<String> = env::args().collect();
match args.len() {
2 => {
let config_path = &args[1];
let config = config::parse(config_path);
debug!("{:?}\n", config);
let hot_deals = rfd::get_hot_deals().map_err(|err| error!("{:?}", err)).ok();
let parsed_deals = rfd::parse_hot_deals(&hot_deals.unwrap());
rfd::match_deals(parsed_deals, config)
}
_ => {
help();
}
}
let app = App::new("rfd-notify")
.version("0.1.0")
.about("Send emails based on regular expressions")
.args(&[
Arg::with_name("config")
.required(true)
.takes_value(true)
.short("c")
.help("Specify path to config")
.long("config"),
Arg::with_name("dbpath")
.default_value("./deals_db")
.takes_value(true)
.short("d")
.help("Specify path to where the embedded database is stored")
.long("dbpath"),
]);
let matches = app.get_matches();
let config = matches.value_of("config").unwrap();
let parsed_config = config::parse(config);
debug!("{:?}\n", parsed_config);
let hot_deals = rfd::get_hot_deals().map_err(|err| error!("{:?}", err)).ok();
let parsed_deals = rfd::parse_hot_deals(&hot_deals.unwrap());
rfd::match_deals(
parsed_deals,
parsed_config,
matches.value_of("dbpath").unwrap(),
);
info!("Complete")
}