Skip to main content

dmc/cli/
build.rs

1use std::path::PathBuf;
2
3use crate::{Engine, engine::config::EngineConfig};
4use dmc_diagnostic::Code;
5use duck_diagnostic::{DiagnosticEngine, print_all_smart};
6
7/// `dmc build`: load config, run the engine once, print the report.
8#[derive(clap::Args)]
9pub struct BuildCmd {
10  #[arg(long, default_value = "dmc.toml")]
11  pub config: PathBuf,
12  #[arg(short, long)]
13  pub strict: bool,
14  #[arg(long)]
15  pub clean: bool,
16}
17
18impl BuildCmd {
19  /// Load config, run the engine once, print the report. `strict` aborts
20  /// on the first validation failure; `clean` wipes `output_dir` first.
21  pub fn run(self) -> std::io::Result<()> {
22    let mut diag_engine = DiagnosticEngine::<Code>::new();
23
24    let mut engine_cfg = EngineConfig::load(&self.config)?;
25    if self.strict {
26      engine_cfg.strict = true;
27    }
28    if self.clean {
29      engine_cfg.clean = true;
30    }
31
32    Engine::run(&engine_cfg, Some(&self.config), &mut diag_engine)?;
33
34    // With-source rendering when the primary label points at a readable
35    // file; compact otherwise (glob/config/IO errors with no source).
36    print_all_smart(&diag_engine, None);
37
38    Ok(())
39  }
40}