1use anyhow::Result;
2use clap::Args;
3use std::collections::BTreeMap;
4
5use crate::platform;
6use crate::testing::runner::get_agent_test_runner;
7
8#[derive(Args, Debug)]
10#[command()]
11pub struct Cli {
12 args: Option<Vec<String>>,
14
15 #[arg(short = 'C', long)]
17 container: bool,
18
19 #[arg(short, long)]
21 env: Option<Vec<String>>,
22}
23
24fn parse_env(env: Vec<String>) -> BTreeMap<String, Option<String>> {
25 env.into_iter()
26 .map(|entry| {
27 #[allow(clippy::map_unwrap_or)] entry
29 .split_once('=')
30 .map(|(k, v)| (k.to_owned(), Some(v.to_owned())))
31 .unwrap_or_else(|| (entry, None))
32 })
33 .collect()
34}
35
36impl Cli {
37 pub fn exec(self) -> Result<()> {
38 let runner = get_agent_test_runner(self.container)?;
39
40 let mut args = vec!["--workspace".to_string()];
41
42 if let Some(mut extra_args) = self.args {
43 args.append(&mut extra_args);
44 }
45
46 if !args.contains(&"--features".to_string()) {
47 let features = platform::default_features();
48 args.extend(["--features".to_string(), features.to_string()]);
49 }
50
51 runner.test(
52 &parse_env(self.env.unwrap_or_default()),
53 &BTreeMap::default(),
54 None,
55 &args,
56 "",
57 )
58 }
59}