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
use anyhow::Result;

use crate::{app, util::ChainArgs as _};

/// Check the Rust code for errors
#[derive(clap::Args, Debug)]
#[command()]
pub struct Cli {
    #[arg(long)]
    clippy: bool,

    #[arg(value_name = "FEATURE")]
    features: Vec<String>,
}

impl Cli {
    pub fn exec(self) -> Result<()> {
        let features = self.features.join(",");
        let features = if self.features.is_empty() {
            "default,all-integration-tests"
        } else {
            &features
        };
        let tool = if self.clippy { "clippy" } else { "check" };
        let args = if self.clippy {
            vec!["--", "-D", "warnings"]
        } else {
            Vec::default()
        };
        app::exec(
            "cargo",
            [
                tool,
                "--workspace",
                "--all-targets",
                "--no-default-features",
                "--features",
                features,
            ]
            .chain_args(args),
            true,
        )
    }
}