From 4fb7fcca7a2af065d6bed740537bc397aa45c0a8 Mon Sep 17 00:00:00 2001 From: Liam <33645555+lj3954@users.noreply.github.com> Date: Fri, 16 Aug 2024 08:48:09 -0700 Subject: [PATCH] feat: Add 'command_exists' precondition type --- Cargo.lock | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++ Cargo.toml | 1 + src/tabs.rs | 5 +++++ 3 files changed, 63 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index b9bed308..142e1b61 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -275,6 +275,16 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" +[[package]] +name = "errno" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + [[package]] name = "filedescriptor" version = "0.8.2" @@ -308,6 +318,15 @@ version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" +[[package]] +name = "home" +version = "0.5.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3d1354bf6b7235cb4a0576c2619fd4ed18183f689b12b006a0ee7329eeff9a5" +dependencies = [ + "windows-sys 0.52.0", +] + [[package]] name = "iana-time-zone" version = "0.1.60" @@ -411,6 +430,12 @@ version = "0.2.155" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" +[[package]] +name = "linux-raw-sys" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" + [[package]] name = "lock_api" version = "0.4.12" @@ -648,6 +673,19 @@ dependencies = [ "winapi", ] +[[package]] +name = "rustix" +version = "0.38.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" +dependencies = [ + "bitflags 2.5.0", + "errno", + "libc", + "linux-raw-sys", + "windows-sys 0.52.0", +] + [[package]] name = "rustversion" version = "1.0.17" @@ -933,6 +971,7 @@ dependencies = [ "tempdir", "toml", "tui-term", + "which", ] [[package]] @@ -1079,6 +1118,18 @@ version = "0.2.92" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "af190c94f2773fdb3729c55b007a722abb5384da03bc0986df4c289bf5567e96" +[[package]] +name = "which" +version = "6.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d9c5ed668ee1f17edb3b627225343d210006a90bb1e3745ce1f30b1fb115075" +dependencies = [ + "either", + "home", + "rustix", + "winsafe", +] + [[package]] name = "winapi" version = "0.3.9" @@ -1267,6 +1318,12 @@ dependencies = [ "winapi", ] +[[package]] +name = "winsafe" +version = "0.0.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d135d17ab770252ad95e9a872d365cf3090e3be864a34ab46f48555993efc904" + [[package]] name = "zerocopy" version = "0.7.34" diff --git a/Cargo.toml b/Cargo.toml index 5a336acf..03a8205c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,6 +16,7 @@ include_dir = "0.7.4" tempdir = "0.3.7" serde = { version = "1.0.205", features = ["derive"] } toml = "0.8.19" +which = "6.0.2" [[bin]] name = "linutil" diff --git a/src/tabs.rs b/src/tabs.rs index 6f32a8dc..97969326 100644 --- a/src/tabs.rs +++ b/src/tabs.rs @@ -50,6 +50,9 @@ impl Entry { == *matches }) } + SystemDataType::CommandExists => values + .iter() + .all(|command| which::which(command).is_ok() == *matches), } }, ) @@ -72,6 +75,8 @@ enum SystemDataType { Environment(String), #[serde(rename = "file")] File(PathBuf), + #[serde(rename = "command_exists")] + CommandExists, } #[derive(Hash, Eq, PartialEq)]