use std::path::PathBuf;
#[derive(Debug, clap::Parser)]
#[command(author, about, version, arg_required_else_help(true))]
pub(crate) struct RootCmd {
#[command(flatten)]
pub(crate) verbose: clap_verbosity_flag::Verbosity,
#[arg(short, long, default_value = ".nedots")]
pub(crate) root: String,
#[arg(short, long = "config", default_value = ".nedots.yml")]
pub(crate) cfg_file: String,
#[arg(short = 'C', long = "configpath")]
pub(crate) cfg_path: Option<PathBuf>,
#[arg(short, long)]
pub(crate) dots: Option<PathBuf>,
#[arg(short, long)]
pub(crate) backups: Option<PathBuf>,
#[command(subcommand)]
cmd: Option<Commands>,
}
#[derive(Debug, clap::Subcommand)]
pub(crate) enum Commands {
Gather(super::gather::GatherCmd),
Backup(super::backup::BackupCmd),
Clean(super::clean::CleanCmd),
Install(super::install::InstallCmd),
Restore(super::restore::RestoreCmd),
}
impl super::Command for RootCmd {
fn init(&self, _: &self::RootCmd) -> Result<crate::config::Config, super::CommandError> {
Ok(crate::config::Config::default())
}
fn run(
&self,
args: &RootCmd,
_config: &crate::config::Config,
) -> Result<(), super::CommandError> {
if let Some(cmd) = &self.cmd {
match cmd {
Commands::Backup(backup_cmd) => {
return backup_cmd.exec(args);
}
Commands::Clean(clean_cmd) => {
return clean_cmd.exec(args);
}
Commands::Gather(gather_cmd) => {
return gather_cmd.exec(args);
}
Commands::Install(install_cmd) => {
return install_cmd.exec(args);
}
Commands::Restore(restore_cmd) => {
return restore_cmd.exec(args);
}
}
}
Ok(())
}
}
#[cfg(test)]
mod test {
use clap::CommandFactory;
#[test]
fn verify() {
super::RootCmd::command().debug_assert()
}
}