1use std::{path::PathBuf, process::Command};
2
3use anyhow::{bail, Result};
4use clap::Args;
5
6use crate::{app::CommandExt as _, features};
7
8#[derive(Args, Debug)]
10#[command()]
11pub struct Cli {
12 #[arg(long, default_value_t = true)]
14 debug: bool,
15
16 #[arg(long)]
18 release: bool,
19
20 #[arg(short = 'F', long)]
22 feature: Vec<String>,
23
24 config: PathBuf,
26
27 args: Vec<String>,
29}
30
31impl Cli {
32 pub(super) fn exec(self) -> Result<()> {
33 if self.debug && self.release {
34 bail!("Can only set one of `--debug` and `--release`");
35 }
36
37 let mut features = features::load_and_extract(&self.config)?;
38 features.extend(self.feature);
39 let features = features.join(",");
40 let mut command = Command::new("cargo");
41 command.args(["run", "--no-default-features", "--features", &features]);
42 if self.release {
43 command.arg("--release");
44 }
45 command.args([
46 "--",
47 "--config",
48 self.config.to_str().expect("Invalid config file name"),
49 ]);
50 command.args(self.args);
51 command.check_run()
52 }
53}