use std::path::Path;
use crate::args::CacheCommand;
use crate::exit::EXIT_ALBA_ERROR;
use crate::render::LineSink;
pub fn run(beamfile: &Path, command: &CacheCommand) -> i32 {
match command {
CacheCommand::Clean => clean(beamfile),
}
}
fn clean(beamfile: &Path) -> i32 {
let dir = super::run::cache_dir(beamfile);
match std::fs::remove_dir_all(&dir) {
Ok(()) => 0,
Err(error) if error.kind() == std::io::ErrorKind::NotFound => 0,
Err(error) => {
LineSink::stderr().line(&format!(
"cannot clean the cache at {}: {error}",
dir.display()
));
EXIT_ALBA_ERROR
}
}
}