use crate::{config::Config, db::Database};
use eyre::WrapErr;
use structopt::StructOpt;
use std::path::PathBuf;
#[derive(StructOpt)]
pub struct Init {
#[structopt(short, long, env = "CYNDIKATOR_CONFIG")]
config: Option<PathBuf>,
#[structopt(short, long)]
update: bool,
}
impl Init {
pub async fn run(self) -> eyre::Result<()> {
let config = Config::load(self.config.as_deref())?;
let mut db = Database::create(config.database_path()?)?;
if self.update {
db.migrate().wrap_err("unable to migrate")?;
}
Ok(())
}
}