Skip to main content

dmc/cli/
build.rs

1use std::path::PathBuf;
2
3use crate::{Engine, engine::config::EngineConfig};
4use dmc_diagnostic::{Code, DiagResult};
5use duck_diagnostic::{Diagnostic, DiagnosticEngine, diag};
6/// `dmc build`: load config, run the engine once, print the report.
7#[derive(clap::Args)]
8pub struct BuildCmd {
9  #[arg(long, default_value = "dmc.toml")]
10  pub config: PathBuf,
11  #[arg(short, long)]
12  pub strict: bool,
13  #[arg(long)]
14  pub clean: bool,
15}
16
17impl BuildCmd {
18  /// Load config, run the engine once, print the report. `strict` aborts
19  /// on the first validation failure; `clean` wipes `output_dir` first.
20  pub fn run(self) -> DiagResult<Diagnostic<Code>> {
21    let mut diag_engine = DiagnosticEngine::<Code>::new();
22    let started = std::time::Instant::now();
23
24    let mut engine_cfg = EngineConfig::load(&self.config)?;
25
26    if self.strict {
27      engine_cfg.strict = true;
28    }
29    if self.clean {
30      engine_cfg.clean = true;
31    }
32
33    Engine::run(&engine_cfg, Some(&self.config), &mut diag_engine)?;
34
35    Ok(diag!(
36      Code::Custom { code: String::from("N001"), severity: duck_diagnostic::Severity::Note },
37      format!("built successfully in {:<.3?}", started.elapsed())
38    ))
39  }
40}