Skip to main content

codebase/
codebase.rs

1//! Describe and generate a small multi-file project.
2//!
3//! ```text
4//! cargo run --example codebase -- /tmp/resrap-codebase
5//! ```
6
7use resrap_rs::{Resrap, templates};
8
9const SPEC: &str = "\
10src/
11  c[2x120 hello_*.c]
12  sql[1x60 schema_*.sql]
13";
14
15fn main() -> Result<(), String> {
16    let target = std::env::args().nth(1).unwrap_or_else(|| ".".to_string());
17
18    let mut resrap = Resrap::new();
19    templates::load(&mut resrap, templates::Lang::C)?;
20    templates::load(&mut resrap, templates::Lang::Sql)?;
21
22    // Parse the DSL (validates it) and write the files under `target`.
23    let root = resrap_rs::parse_dsl(SPEC)?;
24    root.generate_structure(&resrap, &target)?;
25    println!("Generated project in {target}");
26    Ok(())
27}