feat: v0.1.7 add SKIP_CACHE env
This commit is contained in:
2
Cargo.lock
generated
2
Cargo.lock
generated
@@ -128,7 +128,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "runrs"
|
||||
version = "0.1.6"
|
||||
version = "0.1.7"
|
||||
dependencies = [
|
||||
"rust_util",
|
||||
"sha256",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "runrs"
|
||||
version = "0.1.6"
|
||||
version = "0.1.7"
|
||||
edition = "2018"
|
||||
license = "MIT/Apache-2.0"
|
||||
description = "Run Rust Scripts"
|
||||
|
||||
16
src/main.rs
16
src/main.rs
@@ -34,9 +34,11 @@ fn main() {
|
||||
let cache_script_bin_name = format!("{}/Library/Caches/rust-script/binaries/release/{}",
|
||||
home,
|
||||
script_sha256);
|
||||
|
||||
let skip_cache = is_env_on("SKIP_CACHE");
|
||||
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 "));
|
||||
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)
|
||||
} else {
|
||||
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);
|
||||
match util_cmd::run_command_and_wait(&mut cargo_install_rust_script) {
|
||||
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(_) => (),
|
||||
Ok(exist_status) => if !exist_status.success() {
|
||||
failure!("Install rust-script not success: {}", exist_status);
|
||||
},
|
||||
}
|
||||
}
|
||||
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 {
|
||||
env::var("HOME").unwrap_or_else(|_|
|
||||
failure_and_exit!("$HOME not found!")
|
||||
|
||||
Reference in New Issue
Block a user