1use inquire::Confirm;
2use lux_lib::{
3 config::Config,
4 lua_version::LuaVersion,
5 progress::{MultiProgress, ProgressBar},
6 tree::InstallTree,
7};
8use miette::{IntoDiagnostic, Result};
9
10pub async fn purge(config: Config) -> Result<()> {
12 let tree = config.user_tree(LuaVersion::from(&config)?.clone())?;
13
14 let len = tree.list()?.len();
15
16 if !config.no_prompt()
17 && Confirm::new(&format!("Are you sure you want to purge all {len} rocks?"))
18 .with_default(false)
19 .prompt()
20 .into_diagnostic()?
21 {
22 let root_dir = tree.root();
23
24 let progress = MultiProgress::new(&config);
25 let _spinner = progress.map(|progress| {
26 progress.add(ProgressBar::from(format!(
27 "🗑️ Purging {}",
28 root_dir.display()
29 )))
30 });
31 tokio::fs::remove_dir_all(tree.root())
32 .await
33 .into_diagnostic()?;
34 }
35
36 Ok(())
37}