Skip to content

Commit

Permalink
feat: mise rm
Browse files Browse the repository at this point in the history
Fixes #1465
  • Loading branch information
jdx committed Dec 18, 2024
1 parent ab902be commit 8b91a46
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 1 deletion.
6 changes: 6 additions & 0 deletions e2e/cli/test_rm
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env bash

assert "mise use dummy@1.0.0"
assert_contains "mise ls dummy" "1.0.0"
assert "mise rm dummy"
assert_empty "mise ls dummy"
1 change: 1 addition & 0 deletions src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ pub mod version;
mod watch;
mod r#where;
mod r#which;
mod unuse;

#[derive(clap::ValueEnum, Debug, Clone, strum::Display)]
#[strum(serialize_all = "kebab-case")]
Expand Down
2 changes: 1 addition & 1 deletion src/cli/uninstall.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use crate::{config, dirs, file};
///
/// This only removes the installed version, it does not modify mise.toml.
#[derive(Debug, clap::Args)]
#[clap(verbatim_doc_comment, visible_aliases = ["remove", "rm"], after_long_help = AFTER_LONG_HELP)]
#[clap(verbatim_doc_comment, after_long_help = AFTER_LONG_HELP)]
pub struct Uninstall {
/// Tool(s) to remove
#[clap(value_name = "INSTALLED_TOOL@VERSION", required_unless_present = "all")]
Expand Down
72 changes: 72 additions & 0 deletions src/cli/unuse.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
use std::sync::Arc;

use console::style;
use eyre::{bail, eyre, Result};
use itertools::Itertools;
use rayon::prelude::*;

use crate::backend::Backend;
use crate::cli::args::ToolArg;
use crate::config::Config;
use crate::toolset::{ToolRequest, ToolSource, ToolVersion, ToolsetBuilder};
use crate::ui::multi_progress_report::MultiProgressReport;
use crate::{config, dirs, file};

/// Removes installed tool versions from mise.toml
///
/// Will also prune the installed version if no other configurations are using it.
#[derive(Debug, clap::Args)]
#[clap(verbatim_doc_comment, visible_aliases = ["rm", "remove", "unuse"], after_long_help = AFTER_LONG_HELP)]
pub struct Unuse {
/// Tool(s) to remove
#[clap(value_name = "INSTALLED_TOOL@VERSION", required = true)]
installed_tool: Vec<ToolArg>,

/// Do not also prune the installed version
#[clap(long)]
no_prune: bool,

/// Remove tool from global config
#[clap(long)]
global: bool,
}

impl Unuse {
pub fn run(self) -> Result<()> {
// TODO: get the local config containing the requested version
let tool_versions = self.get_requested_tool_versions()?;
let tool_versions = tool_versions
.into_iter()
.unique_by(|(_, tv)| (tv.request.ba().short.clone(), tv.version.clone()))
.collect::<Vec<_>>();

let mpr = MultiProgressReport::get();
for (plugin, tv) in tool_versions {
if !plugin.is_version_installed(&tv, true) {
warn!("{} is not installed", tv.style());
continue;
}

// TODO: only prune if no other configs use it
let pr = mpr.add(&tv.style());
if let Err(err) = plugin.uninstall_version(&tv, pr.as_ref(), false) {
error!("{err}");
return Err(eyre!(err).wrap_err(format!("failed to prune {tv}")));
}
pr.finish_with_message("pruned".into());
}

file::touch_dir(&dirs::DATA)?;
config::rebuild_shims_and_runtime_symlinks(&[])?;

Ok(())
}
}

static AFTER_LONG_HELP: &str = color_print::cstr!(
r#"<bold><underline>Examples:</underline></bold>
# will uninstall specific version
$ <bold>mise remove node@18.0.0</bold>
"#
);

0 comments on commit 8b91a46

Please sign in to comment.