Skip to content

Commit

Permalink
Update outdated.
Browse files Browse the repository at this point in the history
  • Loading branch information
milesj committed Dec 15, 2024
1 parent c11ca57 commit 852afb4
Show file tree
Hide file tree
Showing 6 changed files with 195 additions and 146 deletions.
68 changes: 32 additions & 36 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ extism-pdk = "1.3.0"
http-cache-reqwest = "0.15.0"
human-sort = "0.2.2"
indexmap = "2.7.0"
iocraft = "0.4.1"
iocraft = "0.5.0"
miette = "7.4.0"
once_cell = "1.20.2"
regex = { version = "1.11.1", default-features = false, features = ["std"] }
Expand Down
1 change: 0 additions & 1 deletion crates/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ chrono = "0.4.38"
clap = { workspace = true, features = ["derive", "env"] }
clap_complete = { workspace = true }
clap_complete_nushell = "4.5.4"
comfy-table = "7.1.3"
dialoguer = "0.11.0"
dirs = { workspace = true }
indexmap = { workspace = true }
Expand Down
106 changes: 64 additions & 42 deletions crates/cli/src/commands/clean.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
use crate::helpers::create_theme;
use crate::session::ProtoSession;
use clap::Args;
use dialoguer::Confirm;
use miette::IntoDiagnostic;
use proto_core::PROTO_PLUGIN_KEY;
use proto_core::{Id, ProtoError, Tool, VersionSpec};
use iocraft::prelude::element;
use proto_core::{Id, ProtoError, Tool, VersionSpec, PROTO_PLUGIN_KEY};
use proto_shim::get_exe_file_name;
use rustc_hash::FxHashSet;
use starbase::AppResult;
use starbase_console::ui::*;
use starbase_styles::color;
use starbase_utils::fs;
use std::io::stdout;
Expand Down Expand Up @@ -47,7 +45,13 @@ fn is_older_than_days(now: u128, other: u128, days: u8) -> bool {
}

#[tracing::instrument(skip_all)]
pub async fn clean_tool(mut tool: Tool, now: u128, days: u8, yes: bool) -> miette::Result<usize> {
pub async fn clean_tool(
session: &ProtoSession,
mut tool: Tool,
now: u128,
days: u8,
yes: bool,
) -> miette::Result<usize> {
println!("Checking {}", color::shell(tool.get_name()));

if tool.metadata.inventory.override_dir.is_some() {
Expand Down Expand Up @@ -135,27 +139,33 @@ pub async fn clean_tool(mut tool: Tool, now: u128, days: u8, yes: bool) -> miett

let count = versions_to_clean.len();
let mut clean_count = 0;
let mut confirmed = false;

if count == 0 {
debug!("No versions to remove, continuing to next tool");

return Ok(0);
}

if yes
|| Confirm::with_theme(&create_theme())
.with_prompt(format!(
"Found {} versions, remove {}?",
count,
versions_to_clean
.iter()
.map(|v| color::hash(v.to_string()))
.collect::<Vec<_>>()
.join(", ")
))
.interact()
.into_diagnostic()?
{
session
.console
.render_interactive(element! {
Confirm(
label: format!(
"Found {} versions, remove {}?",
count,
versions_to_clean
.iter()
.map(|v| format!("<hash>{v}</hash>"))
.collect::<Vec<_>>()
.join(", ")
),
value: &mut confirmed,
)
})
.await?;

if yes || confirmed {
for version in versions_to_clean {
tool.set_version(version);
tool.teardown().await?;
Expand Down Expand Up @@ -237,17 +247,23 @@ pub async fn clean_proto(session: &ProtoSession, days: u64) -> miette::Result<us
pub async fn purge_tool(session: &ProtoSession, id: &Id, yes: bool) -> miette::Result<Tool> {
let tool = session.load_tool(id).await?;
let inventory_dir = tool.get_inventory_dir();

if yes
|| Confirm::with_theme(&create_theme())
.with_prompt(format!(
"Purge all of {} at {}?",
tool.get_name(),
color::path(&inventory_dir)
))
.interact()
.into_diagnostic()?
{
let mut confirmed = false;

session
.console
.render_interactive(element! {
Confirm(
label: format!(
"Purge all of {} at <path>{}</path>?",
tool.get_name(),
inventory_dir.display()
),
value: &mut confirmed,
)
})
.await?;

if yes || confirmed {
// Delete inventory
fs::remove_dir_all(inventory_dir)?;

Expand All @@ -270,16 +286,22 @@ pub async fn purge_tool(session: &ProtoSession, id: &Id, yes: bool) -> miette::R
#[tracing::instrument(skip_all)]
pub async fn purge_plugins(session: &ProtoSession, yes: bool) -> AppResult {
let plugins_dir = &session.env.store.plugins_dir;

if yes
|| Confirm::with_theme(&create_theme())
.with_prompt(format!(
"Purge all plugins in {}?",
color::path(plugins_dir)
))
.interact()
.into_diagnostic()?
{
let mut confirmed = false;

session
.console
.render_interactive(element! {
Confirm(
label: format!(
"Purge all plugins in <path>{}</path>?",
plugins_dir.display()
),
value: &mut confirmed,
)
})
.await?;

if yes || confirmed {
fs::remove_dir_all(plugins_dir)?;
fs::create_dir_all(plugins_dir)?;

Expand All @@ -305,7 +327,7 @@ pub async fn internal_clean(
debug!("Finding installed tools to clean up...");

for tool in session.load_tools().await? {
clean_count += clean_tool(tool.tool, now, days, yes).await?;
clean_count += clean_tool(&session, tool.tool, now, days, yes).await?;
}

clean_count += clean_proto(session, days as u64).await?;
Expand Down
Loading

0 comments on commit 852afb4

Please sign in to comment.