From 0d2d057c2264b927b6a6ddb98763d476482c12de Mon Sep 17 00:00:00 2001 From: Nordine Bittich Date: Sat, 10 Jun 2023 23:17:08 +0200 Subject: [PATCH] bash mode --- Cargo.lock | 80 +++------------------------------ Cargo.toml | 4 +- src/cache_command/os_command.rs | 51 ++++++++++++++------- src/cache_command/process.rs | 6 ++- 4 files changed, 49 insertions(+), 92 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 169fa32..d6f17a8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,7 +4,7 @@ version = 3 [[package]] name = "adana" -version = "0.13.26" +version = "0.13.27" dependencies = [ "anyhow", "bincode", @@ -386,11 +386,11 @@ dependencies = [ [[package]] name = "nu-ansi-term" -version = "0.47.0" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1df031e117bca634c262e9bd3173776844b6c17a90b3741c9163663b4385af76" +checksum = "db8e83967c32f9210ce85ac7e9c4b731048c1f51c4262e08bad01af30097a424" dependencies = [ - "windows-sys 0.45.0", + "windows-sys 0.48.0", ] [[package]] @@ -803,37 +803,13 @@ dependencies = [ "windows_x86_64_msvc 0.36.1", ] -[[package]] -name = "windows-sys" -version = "0.45.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "75283be5efb2831d37ea142365f009c02ec203cd29a3ebecbc093d52315b66d0" -dependencies = [ - "windows-targets 0.42.1", -] - [[package]] name = "windows-sys" version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" dependencies = [ - "windows-targets 0.48.0", -] - -[[package]] -name = "windows-targets" -version = "0.42.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e2522491fbfcd58cc84d47aeb2958948c4b8982e9a2d8a2a35bbaed431390e7" -dependencies = [ - "windows_aarch64_gnullvm 0.42.1", - "windows_aarch64_msvc 0.42.1", - "windows_i686_gnu 0.42.1", - "windows_i686_msvc 0.42.1", - "windows_x86_64_gnu 0.42.1", - "windows_x86_64_gnullvm 0.42.1", - "windows_x86_64_msvc 0.42.1", + "windows-targets", ] [[package]] @@ -842,21 +818,15 @@ version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7b1eb6f0cd7c80c79759c929114ef071b87354ce476d9d94271031c0497adfd5" dependencies = [ - "windows_aarch64_gnullvm 0.48.0", + "windows_aarch64_gnullvm", "windows_aarch64_msvc 0.48.0", "windows_i686_gnu 0.48.0", "windows_i686_msvc 0.48.0", "windows_x86_64_gnu 0.48.0", - "windows_x86_64_gnullvm 0.48.0", + "windows_x86_64_gnullvm", "windows_x86_64_msvc 0.48.0", ] -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.42.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c9864e83243fdec7fc9c5444389dcbbfd258f745e7853198f365e3c4968a608" - [[package]] name = "windows_aarch64_gnullvm" version = "0.48.0" @@ -875,12 +845,6 @@ version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9bb8c3fd39ade2d67e9874ac4f3db21f0d710bee00fe7cab16949ec184eeaa47" -[[package]] -name = "windows_aarch64_msvc" -version = "0.42.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c8b1b673ffc16c47a9ff48570a9d85e25d265735c503681332589af6253c6c7" - [[package]] name = "windows_aarch64_msvc" version = "0.48.0" @@ -899,12 +863,6 @@ version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "180e6ccf01daf4c426b846dfc66db1fc518f074baa793aa7d9b9aaeffad6a3b6" -[[package]] -name = "windows_i686_gnu" -version = "0.42.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "de3887528ad530ba7bdbb1faa8275ec7a1155a45ffa57c37993960277145d640" - [[package]] name = "windows_i686_gnu" version = "0.48.0" @@ -923,12 +881,6 @@ version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e2e7917148b2812d1eeafaeb22a97e4813dfa60a3f8f78ebe204bcc88f12f024" -[[package]] -name = "windows_i686_msvc" -version = "0.42.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf4d1122317eddd6ff351aa852118a2418ad4214e6613a50e0191f7004372605" - [[package]] name = "windows_i686_msvc" version = "0.48.0" @@ -947,24 +899,12 @@ version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4dcd171b8776c41b97521e5da127a2d86ad280114807d0b2ab1e462bc764d9e1" -[[package]] -name = "windows_x86_64_gnu" -version = "0.42.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1040f221285e17ebccbc2591ffdc2d44ee1f9186324dd3e84e99ac68d699c45" - [[package]] name = "windows_x86_64_gnu" version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ca2b8a661f7628cbd23440e50b05d705db3686f894fc9580820623656af974b1" -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.42.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "628bfdf232daa22b0d64fdb62b09fcc36bb01f05a3939e20ab73aaf9470d0463" - [[package]] name = "windows_x86_64_gnullvm" version = "0.48.0" @@ -983,12 +923,6 @@ version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c811ca4a8c853ef420abd8592ba53ddbbac90410fab6903b3e79972a631f7680" -[[package]] -name = "windows_x86_64_msvc" -version = "0.42.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "447660ad36a13288b1db4d4248e857b510e8c3a225c822ba4fb748c0aafecffd" - [[package]] name = "windows_x86_64_msvc" version = "0.48.0" diff --git a/Cargo.toml b/Cargo.toml index 888a7bd..aaa8194 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "adana" -version = "0.13.26" +version = "0.13.27" edition = "2021" authors = ["Nordine Bittich"] license = "MIT" @@ -23,7 +23,7 @@ bincode = "1.3.3" dirs = "5.0.1" log = "0.4.18" nom = { version = "7.1.3" } -nu-ansi-term = "0.47.0" +nu-ansi-term = "0.48.0" rustyline = "11.0.0" rustyline-derive = "0.8.0" serde = { version = "1.0.163", features = ['serde_derive', 'rc'] } diff --git a/src/cache_command/os_command.rs b/src/cache_command/os_command.rs index ebfef16..5643a01 100644 --- a/src/cache_command/os_command.rs +++ b/src/cache_command/os_command.rs @@ -53,30 +53,51 @@ fn extract_program(s: &str) -> Res<&str> { pub fn exec_command<'a>( command: &'a str, extra_args: &'a Option<&'a str>, + bash_command: bool, ) -> Res<'a, ()> { - let (remaining, envs) = extract_envs(command)?; - let (remaining, program) = extract_program(remaining)?; + let handle = { + if bash_command { + Command::new("bash") + .args([ + "-c", + &format!( + "{command} {}", + if let Some(extra_args) = extra_args { + extra_args + } else { + "" + } + ), + ]) + .stdout(Stdio::inherit()) + .stderr(Stdio::inherit()) + .spawn() + } else { + let (remaining, envs) = extract_envs(command)?; + let (remaining, program) = extract_program(remaining)?; - let (_, mut args) = extract_args(remaining)?; + let (_, mut args) = extract_args(remaining)?; - if let Some(extra_args) = extra_args { - let (_, mut extra_args) = extract_args(extra_args)?; - args.append(&mut extra_args); - } + if let Some(extra_args) = extra_args { + let (_, mut extra_args) = extract_args(extra_args)?; + args.append(&mut extra_args); + } - let handle = Command::new(program) - .envs(envs) - .args(&args) - .stdout(Stdio::inherit()) - .stderr(Stdio::inherit()) - .spawn(); + Command::new(program) + .envs(envs) + .args(&args) + .stdout(Stdio::inherit()) + .stderr(Stdio::inherit()) + .spawn() + } + }; match handle.and_then(|mut h| h.wait()) { Ok(status) => { debug!("{status}"); } Err(e) => { - eprintln!("{program} failed to start with args {args:?}. err: {e}") + eprintln!("{command} failed to start. err: {e}") } } @@ -89,7 +110,7 @@ mod test { #[test] fn test_exec_command() { - exec_command("echo 'hello world'", &None).unwrap(); + exec_command("echo 'hello world'", &None, false).unwrap(); println!("bye") } } diff --git a/src/cache_command/process.rs b/src/cache_command/process.rs index f7c5021..42de22e 100644 --- a/src/cache_command/process.rs +++ b/src/cache_command/process.rs @@ -108,10 +108,12 @@ pub fn process_command( } CacheCommand::Exec { key, args } => { if let Some(value) = get_value(db, current_cache, key) { - let _ = exec_command(&value, &args) + let _ = exec_command(&value, &args, false) .map_err(|e| anyhow::Error::msg(e.to_string()))?; } else if !key.trim().is_empty() { - return Err(anyhow::Error::msg(format!("{key} not found"))); + exec_command(key, &args, true) + .map_err(|e| anyhow::Error::msg(e.to_string()))?; + //return Err(anyhow::Error::msg(format!("{key} not found"))); } } CacheCommand::Using(key) => {