pipecircuit-cli 0.0.14

Command-line architectural tools for Pipecircuit programs
use std::{
    ffi::OsString,
    io,
    process::{Command, ExitCode},
};

use crate::CliError;

pub(crate) fn execute(
    arguments: Vec<OsString>,
) -> Result<(String, ExitCode), Box<dyn std::error::Error>> {
    let status = Command::new("loopback").args(arguments).status().map_err(|error| {
        if error.kind() == io::ErrorKind::NotFound {
            CliError::new("Loopback is an optional companion. Build it with `loopback/tools/build` in the Pipecircuit repository and put the resulting `loopback` executable and its `pipec-evidence` companion on PATH. Headless pipecircuit commands work without it.")
        } else {
            CliError::new(format!("could not start Loopback: {error}"))
        }
    })?;
    let code = match status.code() {
        Some(code) => u8::try_from(code).unwrap_or(1),
        None => 1,
    };
    Ok((String::new(), ExitCode::from(code)))
}