#!/usr/bin/env bash
# Convert Nickel configuration to YAML
# Usage: ./nickel-to-yaml.sh <input.ncl> [output.yaml]

set -euo pipefail

if [ $# -lt 1 ]; then
    echo "Usage: $0 <input.ncl> [output.yaml]"
    exit 1
fi

INPUT="$1"
OUTPUT="${2:-${INPUT%.ncl}.yaml}"

if [ ! -f "${INPUT}" ]; then
    echo "Error: Input file not found: ${INPUT}"
    exit 1
fi

if ! command -v nickel &> /dev/null; then
    echo "Error: nickel command not found"
    echo "Install with: cargo install nickel"
    exit 1
fi

nickel export --format yaml "${INPUT}" > "${OUTPUT}"
echo "Exported: ${OUTPUT}"
