# Thin control Makefile — one target per ctrl/ script, subcommand as an
# argument. Same shape as rig's, for the same reason: the logic lives in the
# script, never here.
#
#   make up        ->  ctrl/bundle.sh up
#   make bundle down
#
# This directory is a BUNDLE, not an installer. It needs a cluster, which rig
# owns:
#
#   cd .. && make cluster up     # kind cluster for this environment
#   make up                      # then deploy this bundle into it
#
# Start with:  make up

ARGS := $(wordlist 2,$(words $(MAKECMDGOALS)),$(MAKECMDGOALS))
ifneq ($(ARGS),)
$(eval $(ARGS):;@:)
endif

.DEFAULT_GOAL := help
.PHONY: help bundle manifest up down status url list dev

help:                          ## list targets
	@grep -hE '^[a-z]+:.*?##' $(MAKEFILE_LIST) | sed 's/:.*##/\t/' | expand -t16

bundle:                        ## the bundle  [manifest|up|down|status|url|list|dev]
	bash ctrl/bundle.sh $(or $(ARGS),status)

# Shorthands for the ones used constantly.
manifest:                      ## regenerate generated/<slug>.yaml — no cluster needed
	bash ctrl/bundle.sh manifest

up:                            ## deploy this rig (installs MetalLB if absent)
	bash ctrl/bundle.sh up

down:                          ## remove this rig (leaves cluster, MetalLB, siblings)
	bash ctrl/bundle.sh down

status:                        ## what is deployed for this rig
	bash ctrl/bundle.sh status

url:                           ## the address MetalLB assigned
	bash ctrl/bundle.sh url

list:                          ## every rig in this cluster, with addresses
	bash ctrl/bundle.sh list

dev:                           ## run the UI locally with vite — no cluster needed
	bash ctrl/bundle.sh dev
