Skip to main content

dmc/cli/
compile.rs

1use std::path::PathBuf;
2
3use dmc_diagnostic::Code;
4use duck_diagnostic::DiagnosticEngine;
5
6use crate::engine::compile::Compiler;
7
8#[derive(clap::Args)]
9pub struct CompileCmd {
10  #[arg(long, default_value = "dmc.toml")]
11  pub path: PathBuf,
12}
13
14impl CompileCmd {
15  /// Read one mdx file, run the default pipeline, print `CompileOutput`
16  /// as pretty JSON to stdout.
17  pub fn run(self) -> std::io::Result<()> {
18    let mut diag_engine = DiagnosticEngine::<Code>::new();
19
20    let src = std::fs::read_to_string(&self.path)?;
21    let out = Compiler::compile(&src, &mut diag_engine);
22    let json = serde_json::to_string_pretty(&out).unwrap();
23    println!("{}", json);
24    Ok(())
25  }
26}