feat: update runrs

This commit is contained in:
2022-08-06 02:51:02 +08:00
parent efa4f950bf
commit 0e5a26d1f3

View File

@@ -31,10 +31,7 @@ fn main() {
env!("CARGO_PKG_VERSION"),
);
}
let first_argument = match args.get(0) {
None => failure_and_exit!("Must assign file name"),
Some(f) => f,
};
let first_argument = args.get(0).unwrap_or_else(|| failure_and_exit!("Must assign file name"));
if first_argument == "--help" {
println!(r##"{} v{} - {}
@@ -53,17 +50,16 @@ runrs <script.rs> [arguments]
}
let script_file = first_argument;
let script_content = match fs::read_to_string(script_file) {
Err(e) => failure_and_exit!("Read file: {}, failed: {}", script_file, e),
Ok(c) => c,
};
let script_content = fs::read_to_string(script_file).unwrap_or_else(|e|
failure_and_exit!("Read file: {}, failed: {}", script_file, e)
);
let script_sha256 = sha256::digest(script_content);
debugging!("File {} -> sha256: {}", script_file, script_sha256);
let cache_script_bin_name = format!("{}/Library/Caches/rust-script/binaries/release/{}",
home,
script_sha256);
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 {
Command::new(cache_script_bin_name)
} else {