Skip to content

Instantly share code, notes, and snippets.

@gustavohenrique
Created February 1, 2022 18:15
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 gustavohenrique/785495603342b70ba5ef6a38aa124608 to your computer and use it in GitHub Desktop.
Save gustavohenrique/785495603342b70ba5ef6a38aa124608 to your computer and use it in GitHub Desktop.
Auto documentation makefile
.DEFAULT_GOAL := help # Sets default action to be help
define PRINT_HELP_PYSCRIPT # start of Python section
import re, sys
output = []
# Loop through the lines in this file
for line in sys.stdin:
# if the line has a command and a comment start with
# two pound signs, add it to the output
match = re.match(r'^([a-zA-Z_-]+):.*?## (.*)$$', line)
if match:
target, help = match.groups()
output.append("%-10s %s" % (target, help))
# Sort the output in alphanumeric order
output.sort()
# Print the help result
print('\n'.join(output))
endef
export PRINT_HELP_PYSCRIPT # End of python section
help:
@python -c "$$PRINT_HELP_PYSCRIPT" < $(MAKEFILE_LIST)
env: ## Activate the virtual environment
source venv/bin/activate
test: ## Runs the test suite
python manage.py test --thing=stuff
run: ## Start the dev server
python manage.py runserver
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment