fn ensure()

in proto/optional_output_wrapper.rs [24:45]


fn ensure() -> Result<i32, Box<dyn error::Error>> {
    let index = args().position(|a| a == "--").ok_or("no --")?;
    let optional_outputs = args().take(index).collect::<Vec<String>>();
    let exe = args().nth(index + 1).ok_or("no exe")?;
    let exe_args = args().skip(index + 2).collect::<Vec<String>>();
    if exe_args.is_empty() {
        return Err("no exe args".into());
    }
    match Command::new(exe).args(exe_args).status()?.code() {
        Some(code) => {
            if code == 0 {
                for out in optional_outputs {
                    if !Path::new(&out).exists() {
                        let _ = File::create(out)?;
                    }
                }
            }
            Ok(code)
        }
        None => Err("process killed".into()),
    }
}