pub(crate) mod backup;
pub(crate) mod clean;
pub(crate) mod gather;
pub(crate) mod install;
pub(crate) mod nedots;
pub(crate) mod restore;
pub(crate) mod sync;
use crate::config::{read as read_cfg, Config};
use std::path::Path;
pub(crate) trait Command {
fn init(&self, args: &nedots::RootCmd) -> anyhow::Result<Config> {
let mut config: Config;
if let Some(cfg_path) = &args.cfg_path {
config = read_cfg(cfg_path)?;
} else {
let path = Path::new(&args.root).join(Path::new(&args.cfg_file));
config = read_cfg(&path)?;
config.root = Path::new(&args.root).to_path_buf();
}
if let Some(dots_dir) = &args.dots {
config.dots_dir = Path::new(dots_dir).to_path_buf();
}
if let Some(backup_dir) = &args.backups {
config.dots_dir = Path::new(backup_dir).to_path_buf();
}
log::debug!("{:#?}", config);
Ok(config.resolve_paths())
}
fn run(&self, _: &nedots::RootCmd, _: &crate::config::Config) -> anyhow::Result<()>;
fn exec(&self, args: &nedots::RootCmd) -> anyhow::Result<()> {
self.run(args, &self.init(args)?)
}
}