#!/bin/bash
# omarchy:summary=Show or set the OmarchyCN release channel
# omarchy:args=[stable|beta|nightly]
# omarchy:examples=omarchycn channel | omarchycn channel beta

set -euo pipefail

CHANNEL_FILE="$HOME/.config/omarchycn/channel"

if (( $# == 0 )); then
  if [[ -f $CHANNEL_FILE ]]; then
    cat "$CHANNEL_FILE"
  else
    echo "beta (default)"
  fi
  exit 0
fi

case "$1" in
stable | beta | nightly)
  mkdir -p "${CHANNEL_FILE%/*}"
  echo "$1" > "$CHANNEL_FILE"
  echo "Channel: $1"
  ;;
*)
  echo "Unknown channel: $1 (stable|beta|nightly)" >&2
  exit 1
  ;;
esac
