Created
January 20, 2021 19:18
-
-
Save leothelocust/e93336194a48dcf04fcbda0676d8467a to your computer and use it in GitHub Desktop.
An example Makefile with dynamic "help" command
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
COMMAND_COLOR = \033[36m | |
DESC_COLOR = \033[32m | |
CLEAR_COLOR = \033[0m | |
.PHONY: help | |
help: ## prints this message ## (and puts this on line 2) | |
@echo ""; \ | |
echo "Usage: make <command>"; \ | |
echo ""; \ | |
echo "where <command> is one of the following:"; \ | |
echo ""; \ | |
grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | \ | |
perl -nle '/(.*?): ## (.*?) ## (.*$$)/; if ($$3 eq "") { printf ( "$(COMMAND_COLOR)%-20s$(DESC_COLOR)%s$(CLEAR_COLOR)\n\n", $$1, $$2) } else { printf ( "$(COMMAND_COLOR)%-20s$(DESC_COLOR)%s$(CLEAR_COLOR)\n%-20s%s\n\n", $$1, $$2, " ", $$3) }'; | |
.PHONY: other | |
other: ## This description doesn't have a second line, but must end with pound pound ## | |
@echo "Example command..."; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment