#!/usr/bin/env nu

# Validate Nickel Configuration
# Validates Nickel config files using typecheck
# Usage: nu validate-config.nu /path/to/config.ncl

use ansi.nu
use external.nu
use paths.nu

export def main [
    config_path: string  # Path to Nickel config file
]: nothing -> nothing {
    let expanded_path: string = (paths ensure-dir (config_path | path expand | path dirname)) + "/" + ($config_path | path basename)

    paths assert-file-exists $expanded_path

    ansi print-validate $"Validating ($expanded_path)"

    let result: record<exit_code: int, stdout: string, stderr: string> = (external run-cmd "nickel" ["typecheck", $expanded_path])

    if $result.exit_code != 0 {
        ansi print-error "Validation failed"
        print $result.stderr
        exit 1
    }

    ansi print-success $"Validation passed: ($expanded_path)"
}
