Add new command group 'deps' and 'clear-cache' command.

This allows in case of issues with dependencies to at least safely
  remove cached packages. Before that, it could be hard to know where
  are even located the cached files without looking at the source code.

  ```
     Clearing /Users/ktorz/Library/Caches/aiken/packages
     Removing aiken-lang-stdlib-7ca9e659688ea88e1cfdc439b6c20c4c7fae9985.zip
     Removing aiken-lang-stdlib-main@04eb45df3c77f6611bbdff842a0e311be2c56390f0fa01f020d69c93ff567fe5.zip
     Removing aiken-lang-stdlib-6b482fa00ec37fe936c93155e8c670f32288a686.zip
     Removing aiken-lang-stdlib-1cedbe85b7c7e9c4036d63d45cad4ced27b0d50b.zip
         Done
  ```
This commit is contained in:
KtorZ 2023-01-14 16:13:25 +01:00 committed by Lucas
parent 3a5f77da12
commit db22395764
4 changed files with 63 additions and 3 deletions

View File

@ -0,0 +1,38 @@
use aiken_project::{paths, pretty};
use miette::IntoDiagnostic;
use owo_colors::OwoColorize;
use std::fs;
pub fn exec() -> miette::Result<()> {
let dir = paths::packages_cache();
println!(
"{} {}",
pretty::pad_left("Clearing".to_string(), 13, " ")
.bold()
.purple(),
dir.display().bold(),
);
let packages = fs::read_dir(&dir).into_diagnostic()?;
for package in packages {
let path = package.into_diagnostic()?.path();
println!(
"{} {}",
pretty::pad_left("Removing".to_string(), 13, " ")
.bold()
.purple(),
path.file_name()
.unwrap_or_default()
.to_str()
.unwrap_or_default()
.bright_blue(),
);
fs::remove_file(path).into_diagnostic()?;
}
println!(
"{}",
pretty::pad_left("Done".to_string(), 13, " ")
.bold()
.purple()
);
Ok(())
}

View File

@ -0,0 +1,17 @@
pub mod clear_cache;
use clap::Subcommand;
/// Managing project dependencies
#[derive(Subcommand)]
#[clap(setting(clap::AppSettings::DeriveDisplayOrder))]
pub enum Cmd {
/// Clear the system-wide dependencies cache
ClearCache,
}
pub fn exec(cmd: Cmd) -> miette::Result<()> {
match cmd {
Cmd::ClearCache => clear_cache::exec(),
}
}

View File

@ -1,5 +1,6 @@
pub mod build;
pub mod check;
pub mod deps;
pub mod docs;
pub mod error;
pub mod fmt;

View File

@ -1,4 +1,4 @@
use aiken::cmd::{build, check, docs, fmt, lsp, new, tx, uplc};
use aiken::cmd::{build, check, deps, docs, fmt, lsp, new, tx, uplc};
use clap::Parser;
/// Aiken: a smart-contract language and toolchain for Cardano
@ -13,14 +13,17 @@ pub enum Cmd {
Check(check::Args),
Docs(docs::Args),
#[clap(hide = true)]
Lsp(lsp::Args),
#[clap(subcommand)]
Deps(deps::Cmd),
#[clap(subcommand)]
Tx(tx::Cmd),
#[clap(subcommand)]
Uplc(uplc::Cmd),
#[clap(hide = true)]
Lsp(lsp::Args),
}
impl Default for Cmd {
@ -36,6 +39,7 @@ fn main() -> miette::Result<()> {
Cmd::Fmt(args) => fmt::exec(args),
Cmd::Build(args) => build::exec(args),
Cmd::Docs(args) => docs::exec(args),
Cmd::Deps(args) => deps::exec(args),
Cmd::Check(args) => check::exec(args),
Cmd::Lsp(args) => lsp::exec(args),
Cmd::Tx(sub_cmd) => tx::exec(sub_cmd),