Skip to main content

run

Function run 

Source
pub fn run(
    argv: &[String],
    stdin: &mut dyn Read,
    stdout: &mut dyn Write,
    stderr: &mut dyn Write,
) -> i32
Expand description

Run the command over argv, whose first entry is the program name, as std::env::args yields it. Standard input is read only when it is needed, and every line the command prints goes to stdout; a failure is reported on stderr. The return value is the process exit code.

The streams are parameters so the suite can drive the command in process, which is the seam run(argv, console) gives the TypeScript CLI and Run(argv, stdin, out, extra) gives the Go one.

let argv: Vec<String> = ["jsonic", "a:1"].iter().map(|s| s.to_string()).collect();
let mut out: Vec<u8> = Vec::new();
let code = tabnas_jsonic_cli::run(
    &argv,
    &mut std::io::empty(),
    &mut out,
    &mut std::io::sink(),
);
assert_eq!(code, 0);
assert_eq!(String::from_utf8(out).unwrap(), "{\"a\":1}\n");