vdev/commands/
run.rs

1use std::{path::PathBuf, process::Command};
2
3use anyhow::{bail, Result};
4use clap::Args;
5
6use crate::{app::CommandExt as _, features};
7
8/// Run `vector` with the minimum set of features required by the config file
9#[derive(Args, Debug)]
10#[command()]
11pub struct Cli {
12    /// Build and run `vector` in debug mode (default)
13    #[arg(long, default_value_t = true)]
14    debug: bool,
15
16    /// Build and run `vector` in release mode
17    #[arg(long)]
18    release: bool,
19
20    /// Name an additional feature to add to the build
21    #[arg(short = 'F', long)]
22    feature: Vec<String>,
23
24    /// Path to configuration file
25    config: PathBuf,
26
27    /// Non-config arguments to `vector`
28    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}