runscript/
lib.rs

1pub mod parser;
2mod script;
3
4#[doc(inline)]
5pub use script::*;
6
7pub mod exec;
8
9use exec::{ProcessOutput, Verbosity};
10use std::collections::HashMap;
11use std::path::Path;
12use std::process::{Command, Stdio};
13
14/// Alternate definition of `run` for `exec` when it makes a recursive call
15pub(crate) fn run(
16    args: &[&str],
17    cwd: &Path,
18    inherit_verbosity: Verbosity,
19    capture_stdout: bool,
20    env_remap: &HashMap<String, String>,
21) -> Result<ProcessOutput, std::io::Error> {
22    let mut command = Command::new("run");
23    command
24        .args(args)
25        .envs(env_remap)
26        .current_dir(cwd)
27        .stdin(Stdio::inherit())
28        .stdout(if capture_stdout {
29            Stdio::piped()
30        } else {
31            Stdio::inherit()
32        })
33        .stderr(if capture_stdout {
34            Stdio::piped()
35        } else {
36            Stdio::inherit()
37        });
38    match inherit_verbosity {
39        Verbosity::Normal => &mut command,
40        Verbosity::Quiet => command.arg("-q"),
41        Verbosity::Silent => command.arg("-qq"),
42    };
43    let output = command.output()?;
44    Ok(ProcessOutput::from(output))
45}