Add CLI commands and output renderer
Some checks failed
CI / test (push) Failing after 15s
CI / build (push) Has been skipped

This commit is contained in:
2026-02-03 06:56:41 +00:00
parent ca368e64d3
commit 9d1ab5859a

View File

@@ -0,0 +1,68 @@
"""Output rendering for VibeGuard CLI."""
from typing import Any
from rich.console import Console
from rich.panel import Panel
from rich.table import Table
from rich.text import Text
from vibeguard.cli.theme import VibeGuardTheme
class OutputRenderer:
"""Render VibeGuard output using Rich."""
def __init__(self, console: Console | None = None) -> None:
self.console = console or Console(theme=VibeGuardTheme.get_theme())
def render_issue(self, issue: dict[str, Any]) -> None:
"""Render a single issue to the console."""
severity = issue.get("severity", "info")
pattern = issue.get("pattern", "Unknown")
file = issue.get("file", "Unknown")
line = issue.get("line", 0)
message = issue.get("message", "")
suggestion = issue.get("suggestion", "")
content = Text()
content.append(f"[{pattern}]\n", style="pattern")
content.append(f"File: {file}:{line}\n", style="file")
content.append(f"{message}\n\n", style=severity)
if suggestion:
content.append("Fix: ", style="bold")
content.append(f"{suggestion}\n", style="success")
panel = Panel(content, title=f"[{severity}]{pattern}[/{severity}]")
self.console.print(panel)
def render_summary(self, issues: list[dict[str, Any]]) -> None:
"""Render summary of analysis results."""
severity_counts = {"critical": 0, "error": 0, "warning": 0, "info": 0}
for issue in issues:
severity = issue.get("severity", "info")
severity_counts[severity] = severity_counts.get(severity, 0) + 1
table = Table(title="Analysis Summary")
table.add_column("Severity", style="bold")
table.add_column("Count", justify="right")
for severity in ["critical", "error", "warning", "info"]:
count = severity_counts.get(severity, 0)
style = severity if severity != "warning" else "warning"
table.add_row(f"[{style}]{severity.upper()}[/{style}]", str(count))
self.console.print(table)
def render_statistics(self, stats: dict[str, Any]) -> None:
"""Render analysis statistics."""
table = Table(title="Statistics")
table.add_column("Metric")
table.add_column("Value", justify="right")
for key, value in stats.items():
table.add_row(key.replace("_", " ").title(), str(value))
self.console.print(table)