1use std::path::PathBuf;
2
3use crate::{Engine, engine::config::EngineConfig};
4use dmc_diagnostic::{Code, DiagResult};
5use duck_diagnostic::{Diagnostic, DiagnosticEngine, diag};
6
7#[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 pub fn run(self) -> DiagResult<Diagnostic<Code>> {
20 let mut diag_engine = DiagnosticEngine::<Code>::new();
21 let started = std::time::Instant::now();
22
23 let mut engine_cfg = EngineConfig::load(&self.config)?;
24
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 Ok(diag!(
35 Code::Custom { code: String::from("N001"), severity: duck_diagnostic::Severity::Note },
36 format!("built successfully in {:<.3?}", started.elapsed())
37 ))
38 }
39}