use arbitrary::Arbitrary;
use eyre::ensure;
use facet::Facet;
use figue::{self as args};
use tracing::info;
#[derive(Facet, Arbitrary, PartialEq, Debug, Default)]
pub struct InstallArgs {
#[facet(args::named)]
pub sync_dir: Option<String>,
#[facet(args::named, default)]
pub force: bool,
#[facet(args::named, default)]
pub no_daemon: bool,
#[facet(args::named, default)]
pub daemon: bool,
}
impl InstallArgs {
pub fn invoke(self) -> eyre::Result<()> {
ensure!(
!(self.daemon && self.no_daemon),
"`--daemon` and `--no-daemon` cannot be used together"
);
ensure!(
!self.force || self.daemon,
"`--force` requires `--daemon`; plain `install` now configures the sync directory without installing the service"
);
let config = crate::cli::command::service::install_machine_config(self.sync_dir)?;
if self.daemon {
return crate::cli::command::service::install_machine_daemon_service(
&config, self.force,
);
}
info!("Configured machine cache at {}", config.sync_dir.display());
println!("Configured machine cache at {}", config.sync_dir.display());
println!("Run `teamy-mft sync` to publish initial machine-managed snapshots.");
println!("Run `teamy-mft install --daemon` to install the machine daemon service.");
Ok(())
}
}