Skip to content

Instantly share code, notes, and snippets.

@warmwaffles
Last active April 1, 2021 16:54
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 warmwaffles/66a40b7c409e8039149764beaa45e915 to your computer and use it in GitHub Desktop.
Save warmwaffles/66a40b7c409e8039149764beaa45e915 to your computer and use it in GitHub Desktop.
import sys
import re
DOCUMENTATION = re.compile(r"((?:^# [^\n]+\n)+)^([^#:]+):", re.MULTILINE)
STRIP = re.compile(r"(\n)|(#)")
YELLOW = '\033[93m'
GREEN = '\033[32m'
RESET = '\033[0m'
BOLD = '\033[01m'
print(f"{BOLD}Usage:{RESET}")
print(f" make {GREEN}[command]{RESET}")
print(f"{BOLD}Commands:{RESET}")
commands = {}
for makefile in sys.argv[1:]:
with open(makefile, "r") as f:
content = f.read()
for match in DOCUMENTATION.findall(content):
commands[match[1]] = re.sub(STRIP, "", match[0])
largest = 0
for task in commands:
current = len(task)
if current > largest:
largest = current
for task, message in commands.items():
print(f"{YELLOW}{task.rjust(largest)}{RESET} -{message}")
# Some help text here
thing:
@echo boooo
# Show this help.
help:
@python make_help.py $(MAKEFILE_LIST)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment