MCPcopy Create free account
hub / github.com/dylan-sutton-chavez/edge-python / run_script

Function run_script

cli/src/main.rs:98–117  ·  view source on GitHub ↗

Read a script from `file` (or stdin when absent) and run it; a script that raises exits non-zero.

(manifest_path: &Path, file: Option<&Path>)

Source from the content-addressed store, hash-verified

96
97/// Read a script from `file` (or stdin when absent) and run it; a script that raises exits non-zero.
98fn run_script(manifest_path: &Path, file: Option<&Path>) -> Result<()> {
99 let src = match file {
100 Some(p) => std::fs::read_to_string(p).with_context(|| format!("reading {}", p.display()))?,
101 None => {
102 // A bare `edge run` from a terminal would block on stdin forever; force an explicit pipe or path.
103 if std::io::stdin().is_terminal() {
104 bail!("no script given; pass a file path or pipe Python to stdin");
105 }
106 let mut s = String::new();
107 std::io::stdin().read_to_string(&mut s).context("reading stdin")?;
108 s
109 }
110 };
111 let manifest = Manifest::load(manifest_path)?;
112 let code = engine::run(&src, &manifest)?;
113 if code != 0 {
114 std::process::exit(code);
115 }
116 Ok(())
117}

Callers 1

mainFunction · 0.85

Calls 2

loadFunction · 0.85
runFunction · 0.70

Tested by

no test coverage detected