#!/usr/bin/env python3
"""extract doc from a makefile"""

# ############################################################################
# #= BASIC USAGE
#
# .PHONY: help
# help: ## Display help message

import fileinput
import re

BOLD = "\033[1m"
COMMAND_COLOR = "\033[36m"
HEADER_COLOR = "\033[32m"
RESET = "\033[0m"
SECTION_COLOR = "\033[93m"
UNDERLINE = "\033[4m"

print(f"""🌟🌟 {BOLD}{HEADER_COLOR}{UNDERLINE}biocommons conventional make targets{RESET} 🌟🌟

Using these targets promots consistency between local development and ci/cd commands.

usage: make [target ...]""")

for line in fileinput.input():  # noqa: SIM115
    if m := re.match(r"#= (.+)", line):
        print(f"\n{BOLD}{UNDERLINE}{SECTION_COLOR}{m.group(1)}{RESET}")
    elif m := re.match(r"([-\s\w]+):.+?##\s+(.+)", line):
        print(f"{BOLD}{COMMAND_COLOR}{m.group(1):<20}{RESET}{m.group(2)}")
