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
use std::fs;

use anyhow::{bail, Context, Result};

use crate::app;

/// Check that the config/example files are valid
#[derive(clap::Args, Debug)]
#[command()]
pub struct Cli {}

const EXAMPLES: &str = "config/examples";

impl Cli {
    pub fn exec(self) -> Result<()> {
        app::set_repo_dir()?;

        for entry in fs::read_dir(EXAMPLES)
            .with_context(|| format!("Could not read directory {EXAMPLES:?}"))?
        {
            let entry = entry.with_context(|| format!("Could not read entry from {EXAMPLES:?}"))?;
            let filename = entry.path();
            let Some(filename) = filename.as_os_str().to_str() else {
                bail!("Invalid filename {filename:?}");
            };

            let mut command = vec![
                "run",
                "--",
                "validate",
                "--deny-warnings",
                "--no-environment",
            ];
            if entry
                .metadata()
                .with_context(|| format!("Could not get metadata of {filename:?}"))?
                .is_dir()
            {
                command.push("--config-dir");
            }
            command.push(filename);

            app::exec("cargo", command, true)?;
        }

        Ok(())
    }
}