- Create .gitignore to exclude build artifacts - Add README.md with project description and installation instructions - Implement pyproject.toml for package metadata and script entry points - Add console output helpers for command-line scripts - Implement environment file loading functionality - Add JSON file I/O helpers - Create token decoder CLI for decoding JWT claims - Implement serve-markdown CLI for serving Markdown files as HTML
48 lines
1.5 KiB
Python
48 lines
1.5 KiB
Python
"""Colored console output helpers for command-line scripts."""
|
|
|
|
import sys
|
|
|
|
if sys.stdout.isatty():
|
|
COLOR_RESET = "\033[0m"
|
|
COLOR_RED = "\033[0;31m"
|
|
COLOR_GREEN = "\033[0;32m"
|
|
COLOR_YELLOW = "\033[0;33m"
|
|
COLOR_BLUE = "\033[0;34m"
|
|
COLOR_CYAN = "\033[0;36m"
|
|
else:
|
|
COLOR_RESET = COLOR_RED = COLOR_GREEN = COLOR_YELLOW = COLOR_BLUE = COLOR_CYAN = ""
|
|
|
|
|
|
def fail(message):
|
|
"""Print an error message to stderr and exit with status 1.
|
|
|
|
Args:
|
|
message: error text to print.
|
|
"""
|
|
print(f"{COLOR_RED}Error: {message}{COLOR_RESET}", file=sys.stderr)
|
|
sys.exit(1)
|
|
|
|
|
|
def print_banner(title, title_color=COLOR_CYAN):
|
|
"""Print a cyan banner line, the given title, and another banner line.
|
|
|
|
Args:
|
|
title: text to print between the banner lines.
|
|
title_color: color to print the title in; the banner lines themselves are always
|
|
cyan. Defaults to cyan, matching most banners; pass COLOR_GREEN for a
|
|
"Setup/Cleanup Complete!" style closing banner.
|
|
"""
|
|
print(f"{COLOR_CYAN}=========================================={COLOR_RESET}")
|
|
print(f"{title_color}{title}{COLOR_RESET}")
|
|
print(f"{COLOR_CYAN}=========================================={COLOR_RESET}")
|
|
|
|
|
|
def print_summary_counts(pairs):
|
|
"""Print a flat "Label: count" line for each given (label, count) pair.
|
|
|
|
Args:
|
|
pairs: iterable of (label, count) tuples.
|
|
"""
|
|
for label, count in pairs:
|
|
print(f"{label}: {count}")
|