1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
use std::process::Command;

use crate::{
    args::{EnvArgs, WorkspaceArgs},
    config::Config,
    process::CommandExt,
    Result, Run,
};

/// Arguments definition of the `rdme` subcommand.
#[cfg_attr(doc, doc = include_str!("../../doc/cargo-xtask-rdme.md"))]
#[derive(Debug, Clone, Default, clap::Args)]
#[non_exhaustive]
pub struct Rdme {
    /// Environment variables to set for `cargo rdme`.
    #[clap(flatten)]
    pub env_args: EnvArgs,
    /// Workspaces where the `cargo rdme` runs on
    #[clap(flatten)]
    pub workspace_args: WorkspaceArgs,
    /// Options to pass to the `cargo rdme`
    pub extra_options: Vec<String>,
}

impl Run for Rdme {
    fn run(&self, config: &Config) -> Result<()> {
        self.run(config)
    }
}

impl Rdme {
    /// Runs the `rdme` subcommand.
    #[tracing::instrument(name = "rdme", skip_all, err)]
    pub fn run(&self, _config: &Config) -> Result<()> {
        let Self {
            env_args,
            workspace_args,
            extra_options,
        } = self;

        for workspace in workspace_args.workspaces() {
            // cargo rdme <extra_options>
            Command::new("cargo")
                .args(["rdme"])
                .args(extra_options)
                .envs(env_args.env.clone())
                .workspace_spawn(workspace)?;
        }

        Ok(())
    }
}