1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
use crate::common::get_cache_dir;
use anyhow::{Context, Result};
use std::fs;
use structopt::StructOpt;
#[derive(Debug, StructOpt)]
pub enum Cache {
#[structopt(name = "clean")]
Clean,
#[structopt(name = "dir")]
Dir,
}
impl Cache {
pub fn execute(&self) -> Result<()> {
match &self {
Cache::Clean => {
self.clean().context("failed to clean wasmer cache.")?;
}
Cache::Dir => {
self.dir()?;
}
}
Ok(())
}
fn clean(&self) -> Result<()> {
let cache_dir = get_cache_dir();
if cache_dir.exists() {
fs::remove_dir_all(cache_dir.clone())?;
}
fs::create_dir_all(cache_dir)?;
eprintln!("Wasmer cache cleaned successfully.");
Ok(())
}
fn dir(&self) -> Result<()> {
println!("{}", get_cache_dir().to_string_lossy());
Ok(())
}
}