use std::path::PathBuf;
use eyre::{Result, bail};
use crate::system::history::sync::apply::{self, ApplyRequest};
#[derive(Debug, usage_rs::Args)]
#[usage(verbatim_doc_comment, after_long_help = AFTER_LONG_HELP)]
pub(crate) struct DotfilesPull {
#[usage(value_name = "PATH")]
paths: Vec<PathBuf>,
#[usage(long, short = 'n')]
dry_run: bool,
#[usage(long, short = 'y')]
yes: bool,
#[usage(long, value_name = "PATH")]
take_remote: Vec<PathBuf>,
#[usage(long, value_name = "PATH")]
keep_local: Vec<PathBuf>,
}
impl DotfilesPull {
pub(crate) async fn run(self) -> Result<()> {
if !crate::config::Settings::get().history.enabled {
bail!("history is disabled (history.enabled = false)");
}
let (store, tracked, _) = super::history::open().await?;
if let Some(reason) = store.unavailable() {
bail!("cannot apply: {reason}");
}
apply::apply(
&store,
&tracked,
&ApplyRequest {
paths: self.paths.clone(),
dry_run: self.dry_run,
yes: self.yes,
take_remote: self.take_remote.clone(),
keep_local: self.keep_local.clone(),
automatic: false,
plan_only: false,
},
)
.await?;
Ok(())
}
}
static AFTER_LONG_HELP: &str = color_print::cstr!(
r#"<bold><underline>Examples:</underline></bold>
$ <bold>mise bootstrap dotfiles pull --dry-run</bold>
$ <bold>mise bootstrap dotfiles pull --yes</bold>
$ <bold>mise bootstrap dotfiles pull --take-remote ~/.zshrc</bold>
$ <bold>mise bootstrap dotfiles pull --keep-local ~/.zshrc</bold>
"#
);