From 707888a9079459be5065ce9ca7169aea80ad21fa Mon Sep 17 00:00:00 2001 From: refcell Date: Mon, 16 Oct 2023 19:35:50 -0400 Subject: [PATCH] Which checks --- Cargo.lock | 22 ++++++++++++++++++++++ bin/opup/Cargo.toml | 1 + bin/opup/src/deps/manager.rs | 21 ++++----------------- 3 files changed, 27 insertions(+), 17 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f7bac82..f72730b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1141,6 +1141,15 @@ dependencies = [ "digest", ] +[[package]] +name = "home" +version = "0.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5444c27eef6923071f7ebcc33e3444508466a76f7a2b93da00ed6e19f30c1ddb" +dependencies = [ + "windows-sys 0.48.0", +] + [[package]] name = "http" version = "0.2.9" @@ -1784,6 +1793,7 @@ dependencies = [ "tokio", "tracing", "tracing-subscriber", + "which", ] [[package]] @@ -3239,6 +3249,18 @@ version = "0.25.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "14247bb57be4f377dfb94c72830b8ce8fc6beac03cf4bf7b9732eadd414123fc" +[[package]] +name = "which" +version = "4.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87ba24419a2078cd2b0f2ede2691b6c66d8e47836da3b6db8265ebad47afbfc7" +dependencies = [ + "either", + "home", + "once_cell", + "rustix", +] + [[package]] name = "winapi" version = "0.3.9" diff --git a/bin/opup/Cargo.toml b/bin/opup/Cargo.toml index 93f9e26..ee1f8f1 100644 --- a/bin/opup/Cargo.toml +++ b/bin/opup/Cargo.toml @@ -21,6 +21,7 @@ futures.workspace = true tracing.workspace = true tracing-subscriber.workspace = true +which = "4.4.2" humantime = "2.1.0" prettytable-rs = "0.10" semver = { version = "1.0", features = ["serde"] } diff --git a/bin/opup/src/deps/manager.rs b/bin/opup/src/deps/manager.rs index 21978b2..448d3c6 100644 --- a/bin/opup/src/deps/manager.rs +++ b/bin/opup/src/deps/manager.rs @@ -1,5 +1,4 @@ use eyre::Result; -use std::env; use std::path::{Path, PathBuf}; use tracing::instrument; @@ -21,15 +20,14 @@ pub struct DependencyManager; impl DependencyManager { /// Default binaries to check for. - pub const DEFAULT_BINARIES: &'static [&'static str] = - &["docker", "docker-compose", "make", "jq"]; + pub const DEFAULT_BINARIES: &'static [&'static str] = &["docker", "curl", "tar"]; /// Installs binaries that are not in the user's PATH. #[instrument(name = "deps")] pub async fn sync() -> Result<()> { for binary in Self::DEFAULT_BINARIES { tracing::debug!("Checking for {}", binary); - if Self::check_binary(binary).is_some() { + if Self::check_binary(*binary).is_some() { continue; } tracing::warn!("{} not found", binary); @@ -114,20 +112,9 @@ impl DependencyManager { #[instrument(name = "deps", skip(exec_name))] pub fn check_binary

(exec_name: P) -> Option where - P: AsRef, + P: Into, { - env::var_os("PATH").and_then(|paths| { - env::split_paths(&paths) - .filter_map(|dir| { - let full_path = dir.join(&exec_name); - if full_path.is_file() { - Some(full_path) - } else { - None - } - }) - .next() - }) + which::which::(exec_name.into()).ok() } }