use std::path::PathBuf;
use eyre::Result;
use crate::config::config_file::ConfigFile;
use crate::config::config_file::mise_toml::MiseToml;
use crate::config::{ConfigPathOptions, resolve_target_config_path};
use crate::file::display_path;
#[derive(Debug, usage_rs::Args)]
#[usage(verbatim_doc_comment, visible_aliases = ["remove", "rm"], after_long_help = AFTER_LONG_HELP)]
pub(crate) struct SystemBrewUntap {
#[usage(required = true)]
taps: Vec<String>,
#[usage(long, short)]
local: bool,
#[usage(long, short = 'n')]
dry_run: bool,
#[usage(
long,
short,
visible_alias = "file",
value_name = "PATH",
conflicts = "local"
)]
path: Option<PathBuf>,
}
impl SystemBrewUntap {
pub(crate) fn run(self) -> Result<()> {
let path = resolve_target_config_path(ConfigPathOptions {
global: !self.local,
path: self.path,
env: None,
cwd: None,
prefer_toml: true,
prevent_home_local: true,
})?;
if self.dry_run {
for tap in &self.taps {
miseprintln!(
"{}: remove [bootstrap.brew.taps].\"{}\"",
display_path(&path),
tap
);
}
return Ok(());
}
if !path.exists() {
info!(
"{}: no config file found; nothing to remove",
display_path(&path)
);
return Ok(());
}
let mut cf = MiseToml::from_file(&path)?;
for tap in &self.taps {
cf.remove_bootstrap_brew_tap(tap)?;
}
cf.save()?;
info!(
"{}: removed brew taps {}",
display_path(&path),
self.taps.join(", ")
);
Ok(())
}
}
static AFTER_LONG_HELP: &str = color_print::cstr!(
r#"<bold><underline>Examples:</underline></bold>
$ <bold>mise bootstrap packages brew untap railwaycat/emacsmacport</bold>
"#
);