HELM_STARTERS ?= $(HELM_HOME)/starters
CLOUDPOSSE_HELM_STARTER_REPO ?= https://github.com/cloudposse/helm-chart-scaffolding.git
CLOUDPOSSE_HELM_STARTER_REF ?= master
CLOUDPOSSE_HELM_STARTER_NAME ?= cloudposse

SOURCE_CHART_TPL ?= chart

## Fetch starter
helm/chart/starter/fetch:
	@echo "Fetch $(CLOUDPOSSE_HELM_STARTER_NAME) starter"
	@[[ -d "$(HELM_STARTERS)/$(CLOUDPOSSE_HELM_STARTER_NAME)" ]] || \
	  $(GIT) clone $(CLOUDPOSSE_HELM_STARTER_REPO) --branch $(CLOUDPOSSE_HELM_STARTER_REF) $(HELM_STARTERS)/$(CLOUDPOSSE_HELM_STARTER_NAME)

## Remove starter
helm/chart/starter/remove:
	@echo "Remove $(CLOUDPOSSE_HELM_STARTER_NAME) starter"
	@[[ ! -d "$(HELM_STARTERS)/$(CLOUDPOSSE_HELM_STARTER_NAME)" ]] || \
	  rm -rf $(HELM_STARTERS)/$(CLOUDPOSSE_HELM_STARTER_NAME)

## Update starter
helm/chart/starter/update: helm/chart/starter/remove helm/chart/starter/fetch
	@exit 0

## Create chart $CHART from starter scaffold
helm/chart/create:
	$(call assert-set,CHART_NAME)
	$(call assert-set,SOURCE_CHART_TPL)
	@$(HELM) create $(CHART_NAME) -p $(CLOUDPOSSE_HELM_STARTER_NAME)
	@chmod -R 777 $(CHART_NAME)
	@mv $(CHART_NAME) $(SOURCE_CHART_TPL)

