orrery_cli/lib.rs
1//! CLI logic for the Orrery diagram tool.
2//!
3//! Wires together configuration loading, the [`DiagramBuilder`] pipeline,
4//! and file I/O to turn a `.orr` source file into an SVG on disk.
5
6mod args;
7mod config;
8mod error;
9mod source_provider;
10
11pub use args::Args;
12pub use error::Error;
13
14use std::{fs, path::Path};
15
16use bumpalo::Bump;
17use log::info;
18
19use orrery::DiagramBuilder;
20
21use source_provider::FsSourceProvider;
22
23/// Runs the Orrery CLI application.
24///
25/// Loads configuration, parses the input `.orr` file, renders the
26/// resulting diagram to SVG, and writes it to the output path.
27///
28/// # Arguments
29///
30/// * `args` - Command-line arguments.
31/// * `arena` - Bump arena for source text allocation. Must outlive the
32/// returned error, since [`Error::Parse`] borrows from it.
33///
34/// # Errors
35///
36/// Returns [`Error::Parse`] for syntax/validation errors with rich
37/// diagnostics, or [`Error::Render`] for I/O, layout, or export errors.
38pub fn run<'a>(args: &Args, arena: &'a Bump) -> Result<(), Error<'a>> {
39 info!(
40 input_path = args.input,
41 output_path = args.output;
42 "Processing diagram"
43 );
44
45 // Load configuration
46 let app_config = config::load_config(args.config.as_ref())?;
47
48 // Process diagram using DiagramBuilder API
49 let root_path = Path::new(&args.input);
50 let provider = FsSourceProvider::new();
51 let builder = DiagramBuilder::new(app_config, &provider);
52 let diagram = builder.parse(arena, root_path)?;
53 let svg = builder.render_svg(&diagram)?;
54
55 // Write output file
56 fs::write(&args.output, svg)?;
57
58 info!(output_file = args.output; "SVG exported successfully");
59
60 Ok(())
61}