pub fn run<P: AsRef<Path>>(
path: P,
options: ValidateOptions,
adapter: &impl ConfigPort,
) -> Result<ValidateResult>Expand description
Validates a configuration file.
This function performs comprehensive validation of a TOML configuration
file, checking both syntax and semantics. It returns a ValidateResult
containing the parsed theme and any warnings.
§Arguments
path— Path to the configuration file to validateoptions— Configuration for validation behavioradapter— The configuration parser to use
§Returns
Ok(ValidateResult)— Configuration is validErr(FernError)— Configuration has errors
§Errors
Returns an error if:
- The file cannot be read (
FernError::Io) - TOML syntax is invalid (
ConfigError::ParseError) - Values fail validation (
ConfigError::InvalidColor, etc.)
§Example
ⓘ
use fernctl::commands::validate::{run, ValidateOptions};
use fernctl::adapters::TomlConfigAdapter;
use std::path::Path;
let adapter = TomlConfigAdapter::new();
let options = ValidateOptions::default();
match run(Path::new("config.toml"), options, &adapter) {
Ok(result) => {
println!("Configuration is valid!");
println!("Theme variant: {}", result.theme.variant.name());
if !result.warnings.is_empty() {
println!("\nWarnings:");
for warning in &result.warnings {
println!(" - {}", warning);
}
}
}
Err(e) => {
// Error includes rich diagnostic information
eprintln!("{:?}", miette::Report::new(e));
std::process::exit(1);
}
}