From 0e5a26d1f3c597863301bd540dcf8d9ca325c1c9 Mon Sep 17 00:00:00 2001 From: Hatter Jiang Date: Sat, 6 Aug 2022 02:51:02 +0800 Subject: [PATCH] feat: update runrs --- src/main.rs | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/src/main.rs b/src/main.rs index 4c4f4a5..4cd73e7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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 [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 {