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>)
| 96 | |
| 97 | /// Read a script from `file` (or stdin when absent) and run it; a script that raises exits non-zero. |
| 98 | fn 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 | } |