MCPcopy Create free account
hub / github.com/faern/rustscript / run

Function run

src/main.rs:43–68  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

41}
42
43fn run() -> Result<()> {
44 let app = create_app();
45 let matches = app.get_matches();
46 let verbosity_level = matches.occurrences_of("verbose");
47 let recompile = matches.is_present("recompile");
48 let no_run = matches.is_present("no_run");
49 let script_path = matches.value_of("script_path").unwrap();
50 let script_args = values_t!(matches, "script_args", String).unwrap_or(Vec::new());
51
52 let (path_hash, script_hash) =
53 hash::hash_script(&script_path).chain_err(|| "Unable to take signature of script")?;
54
55 let cache = cache::BinCache::new()?;
56 let script_cache_dir = cache.get(path_hash)?;
57 let script_hash_path = script_cache_dir.join("script_hash");
58 let cached_script_hash = file_to_string(&script_hash_path).unwrap_or(String::new());
59 let script_bin_path = script_cache_dir.join(SCRIPT_BIN_PATH);
60 if !script_bin_path.exists() || recompile || script_hash != cached_script_hash {
61 scriptbuilder::build_script_crate(&script_path, &script_cache_dir, verbosity_level > 0).chain_err(|| "Unable to compile the script")?;
62 string_to_file(&script_hash_path, &script_hash)?
63 }
64 if !no_run {
65 runner::run_script(&script_bin_path, script_args)?;
66 }
67 Ok(())
68}
69
70fn file_to_string<P: AsRef<Path>>(path: P) -> Result<String> {
71 let path = path.as_ref();

Callers 1

mainFunction · 0.85

Calls 7

create_appFunction · 0.85
hash_scriptFunction · 0.85
file_to_stringFunction · 0.85
build_script_crateFunction · 0.85
string_to_fileFunction · 0.85
run_scriptFunction · 0.85
getMethod · 0.80

Tested by

no test coverage detected