use clap::Parser;
use face_cli::{Io, cli::Cli, run};
use std::io::Cursor;
#[allow(dead_code)] pub fn drive(args: &[&str], stdin: &str) -> (i32, String, String) {
let cli = Cli::try_parse_from(args).expect("argv parse");
let mut io = Io::new(
Cursor::new(stdin.as_bytes().to_vec()),
Vec::<u8>::new(),
Vec::<u8>::new(),
);
let exit_code = match run(cli, &mut io) {
Ok(()) => 0,
Err(_) => 1,
};
(
exit_code,
String::from_utf8(io.stdout).expect("stdout utf-8"),
String::from_utf8(io.stderr).expect("stderr utf-8"),
)
}
#[allow(dead_code)]
pub fn drive_result(args: &[&str], stdin: &str) -> Result<(String, String), (String, String)> {
let cli = Cli::try_parse_from(args).expect("argv parse");
let mut io = Io::new(
Cursor::new(stdin.as_bytes().to_vec()),
Vec::<u8>::new(),
Vec::<u8>::new(),
);
let outcome = run(cli, &mut io);
let stdout = String::from_utf8(io.stdout).expect("stdout utf-8");
let stderr = String::from_utf8(io.stderr).expect("stderr utf-8");
match outcome {
Ok(()) => Ok((stdout, stderr)),
Err(_) => Err((stdout, stderr)),
}
}
#[allow(dead_code)]
pub fn parses(args: &[&str]) -> bool {
Cli::try_parse_from(args).is_ok()
}