Skip to content

Commit df55b70

Browse files
authored
feat(cli): props injection and batch rendering over the variables system (#56)
Closes #46. --props/--var wired into the existing typed variable system across render/still/validate and the HTML dialect, plus a preflight-validated JSONL batch command with name templates and video-level parallelism.
1 parent 272750e commit df55b70

9 files changed

Lines changed: 1042 additions & 21 deletions

File tree

‎crates/rustmotion-cli/src/commands/batch.rs‎

Lines changed: 514 additions & 0 deletions
Large diffs are not rendered by default.

‎crates/rustmotion-cli/src/commands/mod.rs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
mod batch;
12
mod geometry;
23
mod info;
34
mod render;
@@ -8,6 +9,7 @@ mod validate_attrs;
89
mod validate_schema;
910
pub mod validation;
1011

12+
pub use batch::cmd_batch;
1113
pub use info::cmd_info;
1214
pub use render::{cmd_render, cmd_watch};
1315
pub use schema::cmd_schema;

‎crates/rustmotion-cli/src/commands/validate.rs‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use rustmotion::error::{Result, RustmotionError};
22
use std::path::{Path, PathBuf};
33

44
use super::geometry::{GeometryViolation, ViolationKind};
5-
use super::validation::{self, ValidationReport, ValidationSource};
5+
use super::validation::{self, ValidationReport, ValidationSource, VarOverrides};
66

77
pub fn cmd_validate(
88
input: &PathBuf,
@@ -11,8 +11,9 @@ pub fn cmd_validate(
1111
strict_anim: bool,
1212
strict_attrs: bool,
1313
lenient: bool,
14+
overrides: Option<&VarOverrides>,
1415
) -> Result<()> {
15-
let loaded = match validation::load(ValidationSource::File(input)) {
16+
let loaded = match validation::load_with_vars(ValidationSource::File(input), overrides) {
1617
Ok(l) => l,
1718
Err(e) => {
1819
eprintln!("Error: {}", e);
@@ -49,7 +50,7 @@ pub fn cmd_validate(
4950

5051
// Re-run checks after the fixes so the rest of the function reflects
5152
// the on-disk state.
52-
let reloaded = validation::load(ValidationSource::File(input))?;
53+
let reloaded = validation::load_with_vars(ValidationSource::File(input), overrides)?;
5354
report_out = validation::run_checks(&reloaded, strict_anim);
5455
if strict_attrs {
5556
report_out.promote_attr_warnings();

‎crates/rustmotion-cli/src/commands/validation.rs‎

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use rustmotion::error::{Result, RustmotionError};
1414
use rustmotion::include::{self, IncludeSource};
1515
use rustmotion::schema::{ResolvedScenario, Scenario};
1616
use rustmotion::variables;
17+
use std::collections::HashMap;
1718
use std::path::{Path, PathBuf};
1819

1920
use super::geometry::{validate_geometry, validate_geometry_animated, GeometryViolation};
@@ -25,6 +26,10 @@ pub enum ValidationSource<'a> {
2526
Inline(&'a str),
2627
}
2728

29+
/// Runtime variable overrides from `--props` / `--var` flags.
30+
/// An empty map means "use defaults only".
31+
pub type VarOverrides = HashMap<String, serde_json::Value>;
32+
2833
/// A scenario after parsing, variable resolution, and include resolution.
2934
/// Keeps the raw JSON around so it can be inspected by validators (e.g. for
3035
/// path-based auto-fixes).
@@ -87,6 +92,14 @@ impl ValidationReport {
8792
/// Load + parse + apply variable defaults + resolve includes. Returns the
8893
/// raw JSON (post-substitution) and the resolved scenario.
8994
pub fn load(source: ValidationSource<'_>) -> Result<LoadedScenario> {
95+
load_with_vars(source, None)
96+
}
97+
98+
/// Like [`load`] but injects runtime variable overrides before substitution.
99+
pub fn load_with_vars(
100+
source: ValidationSource<'_>,
101+
overrides: Option<&VarOverrides>,
102+
) -> Result<LoadedScenario> {
90103
let (json_str, source_path, include_source) = match source {
91104
ValidationSource::File(path) => {
92105
let s = std::fs::read_to_string(path).map_err(|e| RustmotionError::FileRead {
@@ -119,7 +132,11 @@ pub fn load(source: ValidationSource<'_>) -> Result<LoadedScenario> {
119132
let mut json_value: serde_json::Value =
120133
serde_json::from_str(&json_str).map_err(RustmotionError::from)?;
121134

122-
variables::apply_defaults(&mut json_value)?;
135+
let label = source_path
136+
.as_ref()
137+
.map(|p| p.display().to_string())
138+
.unwrap_or_else(|| "<inline>".to_string());
139+
variables::apply_variables(&mut json_value, overrides, &label)?;
123140

124141
let scenario: Scenario = serde_json::from_value(json_value.clone())?;
125142
let resolved = include::resolve_includes(scenario, &include_source)?;

0 commit comments

Comments
 (0)