1use eyre::Result;
2use inquire::Confirm;
3use lux_lib::{
4 config::Config,
5 lua_version::LuaVersion,
6 progress::{MultiProgress, ProgressBar},
7 tree::InstallTree,
8};
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 {
21 let root_dir = tree.root();
22
23 let progress = MultiProgress::new(&config);
24 let _spinner = progress.map(|progress| {
25 progress.add(ProgressBar::from(format!(
26 "🗑️ Purging {}",
27 root_dir.display()
28 )))
29 });
30 tokio::fs::remove_dir_all(tree.root()).await?;
31 }
32
33 Ok(())
34}