Skip to content

Commit

Permalink
Polish.
Browse files Browse the repository at this point in the history
  • Loading branch information
milesj committed Aug 15, 2024
1 parent 24f0bff commit 326878e
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 48 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

- Removed `--include-global` and `--only-local` flags from all applicable commands. Use the new `--config-mode` instead.
- WASM API
- Removed the `ToolMetadataOutput.inventory.disable_progress_bars` field.
- Removed the `is_musl` function. Use the host environment instead.
- Deprecated many functions.

Expand Down
38 changes: 13 additions & 25 deletions crates/cli/src/commands/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,11 @@ pub async fn do_install(

let finish_pb = |installed: bool, resolved_version: &VersionSpec| {
if installed {
pb.set_message(format!("Installed {name} {resolved_version}!"));
pb.set_message(format!("{name} {resolved_version} installed!"));
} else {
pb.set_message(format!("{name} {resolved_version} already installed!"));
pb.set_message(color::muted_light(format!(
"{name} {resolved_version} already installed!"
)));
}

if args.id.is_some() {
Expand Down Expand Up @@ -355,7 +357,7 @@ pub async fn do_install(
}

// Sync shell profile
update_shell(&tool, args.passthrough.clone()).await?;
update_shell(tool, args.passthrough.clone()).await?;

Ok(true)
}
Expand All @@ -365,11 +367,6 @@ async fn install_one(session: &ProtoSession, id: &Id, args: InstallArgs) -> miet
debug!(id = id.as_str(), "Loading tool");

let mut tool = session.load_tool(id).await?;

if tool.disable_progress_bars() {
disable_progress_bars();
}

let pb = create_progress_bar(format!("Installing {}", tool.get_name()));

if do_install(&mut tool, args, pb).await? {
Expand Down Expand Up @@ -458,25 +455,16 @@ pub async fn install_all(session: &ProtoSession) -> AppResult {
}
}

let mut install_count = 0;
let mut existing_count = 0;

while let Some(result) = set.join_next().await {
if result.into_diagnostic()?? {
install_count += 1;
} else {
existing_count += 1;
}
}
match result.into_diagnostic() {
Err(error) | Ok(Err(error)) => {
mpb.clear().into_diagnostic()?;
drop(mpb);

if install_count == 0 {
println!("All tools already installed")
} else if existing_count == 0 {
println!("Successfully installed {existing_count} tools!");
} else {
println!(
"Successfully installed {install_count} tools ({existing_count} already installed)!"
);
return Err(error);
}
_ => {}
};
}

Ok(())
Expand Down
6 changes: 1 addition & 5 deletions crates/cli/src/commands/uninstall.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::commands::clean::purge_tool;
use crate::helpers::{create_progress_spinner, disable_progress_bars};
use crate::helpers::create_progress_spinner;
use crate::session::ProtoSession;
use crate::telemetry::{track_usage, Metric};
use clap::Args;
Expand Down Expand Up @@ -75,10 +75,6 @@ pub async fn uninstall(session: ProtoSession, args: UninstallArgs) -> AppResult

debug!("Uninstalling {} with version {}", tool.get_name(), spec);

if tool.disable_progress_bars() {
disable_progress_bars();
}

let pb = create_progress_spinner(format!(
"Uninstalling {} {}",
tool.get_name(),
Expand Down
16 changes: 7 additions & 9 deletions crates/cli/src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use indicatif::{ProgressBar, ProgressStyle};
use miette::IntoDiagnostic;
use starbase_styles::color::{self, Color};
use starbase_utils::env::bool_var;
use std::env;
use std::time::Duration;
use tracing::debug;

Expand Down Expand Up @@ -51,25 +50,24 @@ pub fn create_theme() -> ColorfulTheme {
}
}

// pub fn enable_progress_bars() {
// env::remove_var("PROTO_NO_PROGRESS");
// }
fn format_template_styles(template: &str) -> String {
let pipe = color::muted(" | ");
let slash = color::muted(" / ");

pub fn disable_progress_bars() {
env::set_var("PROTO_NO_PROGRESS", "1");
template.replace(" | ", &pipe).replace(" / ", &slash)
}

pub fn create_progress_bar_style() -> ProgressStyle {
ProgressStyle::default_bar()
.progress_chars("━╾─")
.template("{prefix} {bar:20.183/239} | {msg}")
.template(format_template_styles("{prefix} {bar:20.183/239} | {msg}").as_str())
.unwrap()
}

pub fn create_progress_bar_download_style() -> ProgressStyle {
ProgressStyle::default_bar()
.progress_chars("━╾─")
.template("{prefix} {bar:20.183/239} | {bytes:>5.248} / {total_bytes:5.248} | {bytes_per_sec:>5.183} | {msg}")
.template(format_template_styles("{prefix} {bar:20.183/239} | {bytes:>5.248} / {total_bytes:5.248} | {bytes_per_sec:>5.183} | {msg}").as_str())
.unwrap()
}

Expand All @@ -88,7 +86,7 @@ pub fn create_progress_spinner_style() -> ProgressStyle {

ProgressStyle::default_spinner()
.tick_strings(&chars)
.template("{prefix} {spinner:20.183/239} | {msg}")
.template(format_template_styles("{prefix} {spinner:20.183/239} | {msg}").as_str())
.unwrap()
}

Expand Down
5 changes: 0 additions & 5 deletions crates/core/src/tool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,11 +204,6 @@ impl Tool {
self.version = Some(version);
}

/// Disable progress bars when installing or uninstalling the tool.
pub fn disable_progress_bars(&self) -> bool {
self.metadata.inventory.disable_progress_bars
}

/// Convert a virtual path to a real path.
pub fn from_virtual_path(&self, path: &Path) -> PathBuf {
self.plugin.from_virtual_path(path)
Expand Down
4 changes: 0 additions & 4 deletions crates/pdk-api/src/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,6 @@ api_struct!(
/// Controls aspects of the tool inventory.
#[serde(default)]
pub struct ToolInventoryMetadata {
/// Disable progress bars when installing or uninstalling tools.
#[serde(skip_serializing_if = "is_false")]
pub disable_progress_bars: bool,

/// Override the tool inventory directory (where all versions are installed).
/// This is an advanced feature and should only be used when absolutely necessary.
#[serde(skip_serializing_if = "Option::is_none")]
Expand Down

0 comments on commit 326878e

Please sign in to comment.