Skip to content

Instantly share code, notes, and snippets.

@creisor
Last active June 9, 2020 15:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save creisor/328d4a9fa9dcfc77c19f909be0f9d613 to your computer and use it in GitHub Desktop.
Save creisor/328d4a9fa9dcfc77c19f909be0f9d613 to your computer and use it in GitHub Desktop.
This is how one can prompt for user input in a Makefile (credit: https://stackoverflow.com/a/47839479)
.PHONY: help
help: ## Shows the help
@echo 'Usage: make <TARGETS>'
@echo ''
@echo 'Available targets are:'
@echo ''
@grep -E '^[ a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | \
awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
@echo ''
@echo ''
.PHONY: prompt-apply
prompt-apply :
@( read -p "Apply? [y/N]: " sure && case "$$sure" in [yY]) true;; *) echo "Skipping apply"; false;; esac )
.PHONY: deploy
deploy : diff prompt-apply ## Recompile, show configuration diff, and apply
@echo "APPLY"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment