#!/usr/bin/env nu
# Convert Nickel configuration to JSON (Nushell)
# Usage: ./nickel-to-json.nu <input.ncl> [output.json]

def main [
    input: path,      # Input Nickel file
    output?: path     # Output JSON file (optional)
] {
    let output_path = if ($output == null) {
        $"($input | path parse | get stem).json"
    } else {
        $output
    }

    if not ($input | path exists) {
        error make {msg: $"Input file not found: ($input)"}
    }

    if not ((which nickel | length) > 0) {
        error make {msg: "nickel command not found. Install with: cargo install nickel"}
    }

    ^nickel export --format json $input | save --force $output_path
    print $"Exported: ($output_path)"
}
