Skip to main content

lux_cli/
purge.rs

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