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        tokio::fs::remove_dir_all(tree.root())
23            .instrument(tracing::info_span!(
24                "Purging",
25                tree = root_dir.to_slash_lossy().to_string()
26            ))
27            .await
28            .into_diagnostic()?;
29    }
30
31    Ok(())
32}