Function run

Source
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 validate
  • options — Configuration for validation behavior
  • adapter — The configuration parser to use

§Returns

  • Ok(ValidateResult) — Configuration is valid
  • Err(FernError) — Configuration has errors

§Errors

Returns an error if:

§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);
    }
}