#![expect(
clippy::redundant_pub_crate,
reason = "explicit pub(crate) documents the crate-wide visibility intent at each item"
)]
use std::io::{Read, Write};
use crate::cli::ExtCommand;
pub(crate) fn run(
command: ExtCommand,
stdin: impl Read,
stdout: &mut impl Write,
stderr: &mut impl Write,
) -> i32 {
match command {
ExtCommand::Doctor { dir, flags } => crate::ext_doctor::run(&dir, flags, stdout),
ExtCommand::Fire { dir, event, flags } => {
crate::ext_fire::run(&dir, &event, flags, stdin, stdout, stderr)
}
}
}
#[cfg(test)]
mod tests {
#![expect(
clippy::unwrap_used,
reason = "tests unwrap known-valid fixtures; a panic is the intended failure signal"
)]
use super::run;
use crate::cli::{ExtCommand, ExtFlags};
fn fixture() -> tempfile::TempDir {
let dir = tempfile::tempdir().unwrap();
std::fs::write(
dir.path().join("extension.toml"),
"[extension]\nname='t'\nversion='1'\nentry='main.lua'\napi=1\n",
)
.unwrap();
std::fs::write(dir.path().join("main.lua"), "return 1").unwrap();
dir
}
#[test]
fn doctor_dispatches_to_ext_doctor() {
let dir = fixture();
let mut out = Vec::new();
let mut err = Vec::new();
let code = run(
ExtCommand::Doctor {
dir: dir.path().to_path_buf(),
flags: ExtFlags::default(),
},
&[][..],
&mut out,
&mut err,
);
assert_eq!(code, 0);
let out = String::from_utf8(out).unwrap();
assert!(out.starts_with("extension:"), "{out}");
}
#[test]
fn fire_dispatches_to_ext_fire() {
let dir = fixture();
let mut out = Vec::new();
let mut err = Vec::new();
let code = run(
ExtCommand::Fire {
dir: dir.path().to_path_buf(),
event: "ping".to_owned(),
flags: ExtFlags::default(),
},
&[][..],
&mut out,
&mut err,
);
assert_eq!(code, 0);
}
}