Add clear-cache command

feature/lookup-installed
trivernis 2 years ago
parent 1ac8eec5f3
commit a79eda9387
Signed by: Trivernis
GPG Key ID: DFFFCC2C7A02DB45

@ -20,6 +20,10 @@ pub enum Command {
#[command(short_flag = 'v', aliases = &["--version"])]
Version,
/// Initializes nenv directories and installs a default node version
#[command()]
Init,
/// Installs the given node version
#[command()]
Install(InstallArgs),
@ -43,9 +47,9 @@ pub enum Command {
#[command()]
Exec(ExecArgs),
/// Initializes nenv directories and installs a default node version
/// Clears the download cache
#[command()]
Init,
ClearCache,
}
#[derive(Clone, Debug, Parser)]

@ -48,6 +48,7 @@ async fn main() -> Result<()> {
args::Command::RemapBinaries => nenv.remap().await,
args::Command::ListVersions => nenv.list_versions().await,
args::Command::Init => nenv.init_nenv().await,
args::Command::ClearCache => nenv.clear_cache().await,
_ => xkcd_unreachable!(),
}?;

@ -2,7 +2,7 @@ use std::{ffi::OsString, str::FromStr};
use crate::{
config::ConfigAccess,
consts::{BIN_DIR, VERSION_FILE_PATH},
consts::{BIN_DIR, CACHE_DIR, VERSION_FILE_PATH},
error::VersionError,
mapper::Mapper,
repository::{NodeVersion, Repository},
@ -11,7 +11,7 @@ use crate::{
};
use crossterm::style::Stylize;
use dialoguer::{theme::ColorfulTheme, Input, Select};
use miette::{IntoDiagnostic, Result};
use miette::{Context, IntoDiagnostic, Result};
use tokio::fs;
pub struct Nenv {
@ -138,6 +138,7 @@ impl Nenv {
}
/// Initializes nenv and prompts for a default version.
#[tracing::instrument(skip(self))]
pub async fn init_nenv(&mut self) -> Result<()> {
let items = vec!["latest", "lts", "custom"];
let selection = Select::with_theme(&ColorfulTheme::default())
@ -170,6 +171,22 @@ impl Nenv {
Ok(())
}
/// Clears the download cache
#[tracing::instrument(skip(self))]
pub async fn clear_cache(&self) -> Result<()> {
fs::remove_dir_all(&*CACHE_DIR)
.await
.into_diagnostic()
.context("Removing cache directory")?;
fs::create_dir_all(&*CACHE_DIR)
.await
.into_diagnostic()
.context("Creating cache directory")?;
println!("Cleared download cache.");
Ok(())
}
/// Persits all changes made that aren't written to the disk yet
#[tracing::instrument(level = "debug", skip(self))]
pub async fn persist(&self) -> Result<()> {

Loading…
Cancel
Save