use structopt::StructOpt;
use crate::db::Replace;
use crate::db;
use yansi::Paint;
use pickledb::{PickleDb};
use crate::path;
#[derive(StructOpt, Debug)]
#[structopt(name = "sp")]
pub struct Opt {
#[structopt(short, long)]
pub empty: bool,
#[structopt(short, long)]
pub list: bool,
#[structopt(short, long)]
pub open: Option<String>,
#[structopt(short, long)]
pub find: Option<String>,
#[structopt(short, long)]
pub replace: Option<String>,
#[structopt(short, long)]
pub translate: Option<String>,
}
pub fn option_replace_pairs(opt: &Opt) {
if let (Some(find), Some(replace)) = (&opt.find, &opt.replace) {
db::set_replace_pair(Replace {
find: String::from(find),
replace: String::from(replace)
});
}
}
pub fn option_open(opt: &Opt, db: &PickleDb) {
if let Some(open) = &opt.open {
path::open(&open, &db)
}
}
pub fn option_translate(opt: &Opt, db: &PickleDb) {
if let Some(translate) = &opt.translate {
path::translate(&translate, &db);
}
}
pub fn option_list(opt: &Opt, db: &PickleDb) {
if opt.list {
path::list(&db);
}
}
pub fn option_empty(opt: &Opt, mut db: PickleDb) {
if opt.empty {
db.rem("replace_pairs").unwrap();
println!("{}", Paint::green("The replace pairs were emptied."));
}
}