feat: v0.1.7 add SKIP_CACHE env

This commit is contained in:
2022-08-06 13:22:28 +08:00
parent 20287855b4
commit bb80fbabc9
3 changed files with 15 additions and 5 deletions

2
Cargo.lock generated
View File

@@ -128,7 +128,7 @@ dependencies = [
[[package]] [[package]]
name = "runrs" name = "runrs"
version = "0.1.6" version = "0.1.7"
dependencies = [ dependencies = [
"rust_util", "rust_util",
"sha256", "sha256",

View File

@@ -1,6 +1,6 @@
[package] [package]
name = "runrs" name = "runrs"
version = "0.1.6" version = "0.1.7"
edition = "2018" edition = "2018"
license = "MIT/Apache-2.0" license = "MIT/Apache-2.0"
description = "Run Rust Scripts" description = "Run Rust Scripts"

View File

@@ -34,9 +34,11 @@ fn main() {
let cache_script_bin_name = format!("{}/Library/Caches/rust-script/binaries/release/{}", let cache_script_bin_name = format!("{}/Library/Caches/rust-script/binaries/release/{}",
home, home,
script_sha256); script_sha256);
let skip_cache = is_env_on("SKIP_CACHE");
let cache_script_bin_name_exists = fs::metadata(&cache_script_bin_name).is_ok(); let cache_script_bin_name_exists = fs::metadata(&cache_script_bin_name).is_ok();
debugging!("Bin name: {} {}exists", cache_script_bin_name, iff!(cache_script_bin_name_exists, "", "not ")); debugging!("Bin name: {} {}exists", cache_script_bin_name, iff!(cache_script_bin_name_exists, "", "not "));
let mut run_script_cmd = if cache_script_bin_name_exists { let mut run_script_cmd = if !skip_cache && cache_script_bin_name_exists {
Command::new(&cache_script_bin_name) Command::new(&cache_script_bin_name)
} else { } else {
let mut cmd = Command::new(rust_script); let mut cmd = Command::new(rust_script);
@@ -93,13 +95,21 @@ fn get_run_script_bin_name(home: &str) -> PathBuf {
debugging!("Run command: {:?}", cargo_install_rust_script); debugging!("Run command: {:?}", cargo_install_rust_script);
match util_cmd::run_command_and_wait(&mut cargo_install_rust_script) { match util_cmd::run_command_and_wait(&mut cargo_install_rust_script) {
Err(e) => failure_and_exit!("Install rust-script failed: {}", e), Err(e) => failure_and_exit!("Install rust-script failed: {}", e),
Ok(exist_status) if !exist_status.success() => failure!("Install rust-script not success: {}", exist_status), Ok(exist_status) => if !exist_status.success() {
Ok(_) => (), failure!("Install rust-script not success: {}", exist_status);
},
} }
} }
rust_script rust_script
} }
fn is_env_on(env: &str) -> bool {
env::var(env).map(|v| {
let v = v.to_string();
v == "true" || v == "on" || v == "yes" || v == "1"
}).unwrap_or_else(|_| false)
}
fn get_user_home() -> String { fn get_user_home() -> String {
env::var("HOME").unwrap_or_else(|_| env::var("HOME").unwrap_or_else(|_|
failure_and_exit!("$HOME not found!") failure_and_exit!("$HOME not found!")