From 5d40e95450e5b893de7407f75a869b76f377e940 Mon Sep 17 00:00:00 2001 From: penguinboi Date: Sat, 2 May 2026 04:14:45 -0400 Subject: [PATCH] Add verify command in cli # Conflicts: # bot/cli.py --- bot/cli.py | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/bot/cli.py b/bot/cli.py index 1ddeccf..7be6467 100644 --- a/bot/cli.py +++ b/bot/cli.py @@ -1,5 +1,8 @@ from os import getenv -from click import UsageError, pass_context, group, option +import subprocess +import sys + +from click import UsageError, pass_context, group, option, echo, style from pelican import use_context from pelican.cli import cli as pelican_cli @@ -25,6 +28,9 @@ def resolve_config_path(env: str | None) -> str: def cli(ctx, env: str | None, config_file: str | None) -> None: ctx.ensure_object(dict) + if ctx.invoked_subcommand == "verify": + return + if env and config_file: raise UsageError("Use either --env or --config, not both.") @@ -50,3 +56,35 @@ def db(): # we add each pelican command to the db group for cmd in pelican_cli.commands.values(): db.add_command(cmd) + + +@cli.command("verify", help="Verify the codebase is clean") +def verify_command() -> None: + ok = style("✓", fg="green", bold=True) + fail = style("✗", fg="red", bold=True) + overall_exit = 0 + + steps = [ + ( + "black ", + "checking formatting...", + ["black", "--check", "bot/", "tests/", "db/"], + ), + ("mypy ", "type checking...", ["mypy", "bot/", "tests/"]), + ("pytest", "running tests...", ["pytest", "tests/", "--color=yes"]), + ] + + for label, description, args in steps: + echo(style(label, bold=True) + f" {description}", nl=False) + result = subprocess.run(args, capture_output=True, text=True) + + if result.returncode == 0: + echo(f" {ok}") + else: + echo(f" {fail}") + + if output := (result.stdout + result.stderr).strip(): + echo(output) + overall_exit = result.returncode + + sys.exit(overall_exit)