Add list-runs CLI command

This commit is contained in:
2026-01-29 18:00:37 +00:00
parent bff13cd616
commit 022223af76

View File

@@ -125,6 +125,89 @@ def run_test_cmd(
)
@app.command(name="list-runs")
def list_runs_cmd(
config_file: Annotated[
str | None,
typer.Option("--config", "-c", help="Path to configuration YAML file."),
] = None,
limit: Annotated[
int,
typer.Option("--limit", "-n", help="Maximum number of runs to display."),
] = 20,
) -> None:
"""List recent test runs with their IDs.
Shows a table of recent test runs including the short ID (for use with
export-report), test name, status, and timestamp.
"""
from pathlib import Path
from rich.console import Console
from rich.table import Table
from py_dvt_ate.app.config import load_config
from py_dvt_ate.data.repository import SQLiteRepository
console = Console()
# Load config
if config_file is None:
config_path = Path("config/default.yaml")
if config_path.exists():
config_file = str(config_path)
config = load_config(config_file)
# Create repository
repo = SQLiteRepository(
db_path=config.data.database_path,
measurements_dir=config.data.measurements_dir,
)
try:
runs = repo.get_all_runs()
if not runs:
console.print("[yellow]No test runs found.[/yellow]")
return
# Limit results
runs = runs[:limit]
# Create table
table = Table(title="Recent Test Runs")
table.add_column("ID", style="cyan", no_wrap=True)
table.add_column("Test Name", style="white")
table.add_column("Status", style="white")
table.add_column("Started", style="dim")
for run in runs:
# Format status with colour
status = run.status.value.upper()
if status == "PASSED":
status_styled = f"[green]{status}[/green]"
elif status == "FAILED":
status_styled = f"[red]{status}[/red]"
elif status == "ERROR":
status_styled = f"[yellow]{status}[/yellow]"
else:
status_styled = status
table.add_row(
run.id[:8],
run.test_name,
status_styled,
run.started_at.strftime("%Y-%m-%d %H:%M:%S"),
)
console.print(table)
console.print(f"\n[dim]Showing {len(runs)} of {len(repo.get_all_runs())} runs[/dim]")
finally:
repo.close()
@app.command(name="query")
def query_cmd(
instrument: Annotated[