Skip to main content

lux_cli/
purge.rs

1use inquire::Confirm;
2use lux_lib::{config::Config, lua_version::LuaVersion, tree::InstallTree};
3
4use miette::{IntoDiagnostic, Result};
5use path_slash::PathBufExt;
6use tracing::Instrument;
7
8/// Purge the user tree
9pub async fn purge(config: Config) -> Result<()> {
10    let tree = config.user_tree(LuaVersion::from(&config)?.clone())?;
11
12    let len = tree.list()?.len();
13
14    if !config.no_prompt()
15        && Confirm::new(&format!("Are you sure you want to purge all {len} rocks?"))
16            .with_default(false)
17            .prompt()
18            .into_diagnostic()?
19    {
20        let root_dir = tree.root();
21
22        let span = tracing::info_span!("🗑️ Purging", tree = root_dir.to_slash_lossy().to_string());
23        tokio::fs::remove_dir_all(tree.root())
24            .instrument(span)
25            .await
26            .into_diagnostic()?;
27    }
28
29    Ok(())
30}