-
Notifications
You must be signed in to change notification settings - Fork 356
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #1465
- Loading branch information
Showing
4 changed files
with
80 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
"# | ||
); |