浏览代码

🐍 Why not generating `make`s help in Python?

master
David Larlet 2 年前
父节点
当前提交
d7d9526c5e
共有 1 个文件被更改,包括 21 次插入1 次删除
  1. 21
    1
      Makefile

+ 21
- 1
Makefile 查看文件

@@ -4,6 +4,26 @@ include .env

SERVER_OUTPUT = $(TARGET_SERVER_OUTPUT) # user@server.url:/path/to/website

# See https://daniel.feldroy.com/posts/autodocumenting-makefiles
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("\033[36m%-10s\033[0m %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

.PHONY: install
install: ## Install the dependencies to build the website
python -m pip install -r requirements.txt
@@ -31,4 +51,4 @@ publish: build ## Publish the website online (rsync)

.PHONY: help
help:
@grep -h -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
@python -c "$$PRINT_HELP_PYSCRIPT" < $(MAKEFILE_LIST)

正在加载...
取消
保存