#!/bin/sh

# This script parses the projects list from config.yaml using yq
# It outputs a space-separated list of projects

die() {
    >&2 echo "error: $*"
    exit 1
}

if ! command -v yq >/dev/null 2>&1; then
    die "yq is not installed. Please install yq to parse YAML files."
fi

CONFIG_FILE="$1"
[ -z "$CONFIG_FILE" ] && die "config file not specified"
[ -f "$CONFIG_FILE" ] || die "config file not found: $CONFIG_FILE"

# Parse projects list from config.yaml
PROJECTS=$(yq -r '.projects | join(" ")' "$CONFIG_FILE")

# Check if projects list is empty
[ -z "$PROJECTS" ] && die "projects list is empty in $CONFIG_FILE"

echo "$PROJECTS"