Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 39 additions & 1 deletion bot/cli.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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.")

Expand All @@ -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)
Loading