Skip to content

Commit

Permalink
Which checks
Browse files Browse the repository at this point in the history
  • Loading branch information
refcell committed Oct 16, 2023
1 parent 73006a8 commit 707888a
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 17 deletions.
22 changes: 22 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions bin/opup/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand Down
21 changes: 4 additions & 17 deletions bin/opup/src/deps/manager.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use eyre::Result;
use std::env;
use std::path::{Path, PathBuf};
use tracing::instrument;

Expand All @@ -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);
Expand Down Expand Up @@ -114,20 +112,9 @@ impl DependencyManager {
#[instrument(name = "deps", skip(exec_name))]
pub fn check_binary<P>(exec_name: P) -> Option<PathBuf>
where
P: AsRef<Path>,
P: Into<String>,
{
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::<String>(exec_name.into()).ok()
}
}

Expand Down

0 comments on commit 707888a

Please sign in to comment.