use std::{path::PathBuf, sync::OnceLock};
use snapbox::cmd::Command;
static BASIC_EXAMPLE: OnceLock<PathBuf> = OnceLock::new();
static ARGUMENTS_EXAMPLE: OnceLock<PathBuf> = OnceLock::new();
static COMMANDS_EXAMPLE: OnceLock<PathBuf> = OnceLock::new();
pub(crate) fn example_command(name: &str) -> Command {
let binary = match name {
"basic" => BASIC_EXAMPLE.get_or_init(|| compile_example("basic")),
"arguments" => ARGUMENTS_EXAMPLE.get_or_init(|| compile_example("arguments")),
"commands" => COMMANDS_EXAMPLE.get_or_init(|| compile_example("commands")),
other => panic!("unsupported CLI-test example `{other}`"),
};
Command::new(binary).env("NO_COLOR", "1")
}
fn compile_example(name: &str) -> PathBuf {
snapbox::cmd::compile_example(name, ["--all-features"])
.unwrap_or_else(|error| panic!("failed to compile {name} example: {error}"))
}