Skip to content

Commit

Permalink
Polish.
Browse files Browse the repository at this point in the history
  • Loading branch information
milesj committed Dec 18, 2024
1 parent e939755 commit 50484c3
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 22 deletions.
8 changes: 3 additions & 5 deletions crates/cli/src/commands/clean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ use starbase::AppResult;
use starbase_console::ui::*;
use starbase_styles::color;
use starbase_utils::fs;
use std::io::stdout;
use std::io::IsTerminal;
use std::time::{Duration, SystemTime};
use tracing::debug;

Expand Down Expand Up @@ -325,14 +323,14 @@ pub async fn internal_clean(

#[tracing::instrument(skip_all)]
pub async fn clean(session: ProtoSession, args: CleanArgs) -> AppResult {
let force_yes = args.yes || !stdout().is_terminal();
let skip_prompts = session.skip_prompts(args.yes);

if args.purge_plugins {
purge_plugins(&session, force_yes).await?;
purge_plugins(&session, skip_prompts).await?;
return Ok(None);
}

internal_clean(&session, args, force_yes, true).await?;
internal_clean(&session, args, skip_prompts, true).await?;

Ok(None)
}
31 changes: 17 additions & 14 deletions crates/cli/src/commands/outdated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,23 +248,26 @@ pub async fn outdated(session: ProtoSession, args: OutdatedArgs) -> AppResult {
return Ok(None);
}

let skip_prompts = session.skip_prompts(args.yes);
let mut confirmed = false;

session
.console
.render_interactive(element! {
Confirm(
label: if args.latest {
"Update config files with latest versions?"
} else {
"Update config files with newest versions?"
},
value: &mut confirmed,
)
})
.await?;
if !skip_prompts {
session
.console
.render_interactive(element! {
Confirm(
label: if args.latest {
"Update config files with latest versions?"
} else {
"Update config files with newest versions?"
},
value: &mut confirmed,
)
})
.await?;
}

if args.yes || confirmed {
if skip_prompts || confirmed {
let mut updates: BTreeMap<PathBuf, BTreeMap<Id, UnresolvedVersionSpec>> = BTreeMap::new();

for (id, item) in &items {
Expand Down
11 changes: 8 additions & 3 deletions crates/cli/src/commands/uninstall.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ pub async fn uninstall_all(session: ProtoSession, args: UninstallArgs) -> AppRes
let tool = session.load_tool(&args.id).await?;
let inventory_dir = tool.get_inventory_dir();
let version_count = tool.inventory.manifest.installed_versions.len();
let skip_prompts = session.skip_prompts(args.yes);
let mut confirmed = false;

if !inventory_dir.exists() {
Expand All @@ -87,7 +88,7 @@ pub async fn uninstall_all(session: ProtoSession, args: UninstallArgs) -> AppRes
return Ok(Some(1));
}

if !args.yes {
if !skip_prompts {
session
.console
.render_interactive(element! {
Expand All @@ -104,10 +105,13 @@ pub async fn uninstall_all(session: ProtoSession, args: UninstallArgs) -> AppRes
.await?;
}

if !args.yes && !confirmed {
if !skip_prompts && !confirmed {
return Ok(None);
}

let progress = session.render_progress_loader()?;
progress.set_message(format!("Uninstalling {}", tool.get_name()));

// Delete bins
for bin in tool.resolve_bin_locations(true).await? {
session.env.store.unlink_bin(&bin.path)?;
Expand All @@ -122,6 +126,8 @@ pub async fn uninstall_all(session: ProtoSession, args: UninstallArgs) -> AppRes
fs::remove_dir_all(inventory_dir)?;
fs::remove_dir_all(tool.get_temp_dir())?;

progress.stop().await?;

unpin_version(&session, &args)?;
track_uninstall(&tool, true).await?;

Expand Down Expand Up @@ -165,7 +171,6 @@ pub async fn uninstall_one(
debug!("Uninstalling {} with version {}", tool.get_name(), spec);

let progress = session.render_progress_loader()?;

progress.set_message(format!(
"Uninstalling {} <hash>{}</hash>",
tool.get_name(),
Expand Down
5 changes: 5 additions & 0 deletions crates/cli/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use starbase::{AppResult, AppSession};
use starbase_console::ui::{style_to_color, ConsoleTheme, ProgressLoader, ProgressReporter};
use starbase_console::{Console, EmptyReporter};
use starbase_styles::Style;
use std::io::IsTerminal;
use std::sync::Arc;
use tokio::task::JoinSet;
use tracing::debug;
Expand Down Expand Up @@ -207,6 +208,10 @@ impl ProtoSession {

Ok(ProgressInstance { reporter, handle })
}

pub fn skip_prompts(&self, yes: bool) -> bool {
yes || !std::io::stdout().is_terminal()
}
}

#[async_trait]
Expand Down

0 comments on commit 50484c3

Please sign in to comment.