prax_cli/schema_loader.rs
1//! Shared schema-loading helper used by every CLI command.
2//!
3//! Resolves the schema path (from --schema arg or default), then delegates to
4//! `prax_schema::load` which auto-detects file vs. directory.
5
6use std::path::{Path, PathBuf};
7
8use prax_schema::{LoadedSchema, load};
9
10use crate::config::SCHEMA_FILE_PATH;
11use crate::error::CliResult;
12
13/// Load the schema, preferring `args_path` if Some, falling back to the
14/// configured / default schema path.
15pub fn load_schema(args_path: Option<&Path>) -> CliResult<LoadedSchema> {
16 let path: PathBuf = args_path
17 .map(PathBuf::from)
18 .unwrap_or_else(|| PathBuf::from(SCHEMA_FILE_PATH));
19 Ok(load(&path)?)
20}