#!/usr/bin/env bash
# argo-cd/argo-rollouts 2.40.9 - base variant: default
# Path: render this base variant locally, then upload the objects to your
# ConfigHub Space as Units you can edit, diff, and deliver.
# Needs a ConfigHub account: run cub auth login once before this script.
# Generated by scripts/generate-public-site.mjs from the committed package
# data for this base variant. Chart page: https://confighub.github.io/helm-expt/site/charts/argo-cd-argo-rollouts-2-40-9.html
set -euo pipefail

say() { printf '\n>> %s\n' "$*"; }

if ! command -v cub >/dev/null 2>&1; then
  printf 'cub is not installed. Install the cub CLI with:\n  curl -fsSL https://hub.confighub.com/cub/install.sh | bash\nthen add ~/.confighub/bin to your PATH and re-run this script.\n' >&2
  exit 1
fi

# Installer is a cub plugin. Check it before this script does any work.
if ! cub installer --help >/dev/null 2>&1; then
  printf 'The cub installer plugin is missing. Follow https://confighub.github.io/helm-expt/site/try.html#install-cub, then re-run this script.\n' >&2
  exit 1
fi

if ! command -v kustomize >/dev/null 2>&1; then
  printf 'kustomize is missing. Follow https://confighub.github.io/helm-expt/site/try.html#install-cub, then re-run this script.\n' >&2
  exit 1
fi

SPACE="${CUB_SPACE:-helm-argo-rollouts-default}"

say "Check ConfigHub auth"
if ! cub auth status >/dev/null 2>&1; then
  printf 'Not logged in. Run: cub auth login\nThen re-run this script.\n' >&2
  exit 1
fi

say "Render the default base variant into ./argo-cd-argo-rollouts-2-40-9-default"
cub installer setup --pull oci://europe-west1-docker.pkg.dev/nth-fort-499605-q5/helm-expt/argo-cd-argo-rollouts:2.40.9 --base default --work-dir ./argo-cd-argo-rollouts-2-40-9-default --non-interactive --namespace default

say "Upload the rendered objects to Space ${SPACE} (created on first upload)"
cub installer upload --work-dir ./argo-cd-argo-rollouts-2-40-9-default --space "${SPACE}"

say "Uploaded. See your Units:"
printf '  cub unit list --space %s\n  or open https://hub.confighub.com and find that Space.\n' "${SPACE}"

say "Next: create an environment variant and promote reviewed changes"
printf '  Walkthrough with the why behind each flag:\n  https://confighub.github.io/helm-expt/site/d/docs/user/variants-after-upload.html\n'
