use anyhow::Result;
use clap::Args;
use std::collections::BTreeMap;
use crate::platform;
use crate::testing::runner::get_agent_test_runner;
#[derive(Args, Debug)]
#[command()]
pub struct Cli {
args: Option<Vec<String>>,
#[arg(short = 'C', long)]
container: bool,
#[arg(short, long)]
env: Option<Vec<String>>,
}
fn parse_env(env: Vec<String>) -> BTreeMap<String, Option<String>> {
env.into_iter()
.map(|entry| {
#[allow(clippy::map_unwrap_or)] entry
.split_once('=')
.map(|(k, v)| (k.to_owned(), Some(v.to_owned())))
.unwrap_or_else(|| (entry, None))
})
.collect()
}
impl Cli {
pub fn exec(self) -> Result<()> {
let runner = get_agent_test_runner(self.container)?;
let mut args = vec!["--workspace".to_string()];
if let Some(mut extra_args) = self.args {
args.append(&mut extra_args);
}
if !args.contains(&"--features".to_string()) {
let features = platform::default_features();
args.extend(["--features".to_string(), features.to_string()]);
}
runner.test(
&parse_env(self.env.unwrap_or_default()),
&BTreeMap::default(),
None,
&args,
"",
)
}
}