Coverage for lintro / cli_utils / commands / versions.py: 19%
48 statements
« prev ^ index » next coverage.py v7.13.0, created at 2026-04-03 18:53 +0000
« prev ^ index » next coverage.py v7.13.0, created at 2026-04-03 18:53 +0000
1"""Versions command for displaying tool version information."""
3import json
5import click
6from rich.console import Console
7from rich.table import Table
9from lintro.tools.core.version_requirements import get_all_tool_versions
12@click.command()
13@click.option(
14 "--verbose",
15 "-v",
16 is_flag=True,
17 help="Show detailed version information including install hints.",
18)
19@click.option(
20 "--json",
21 "json_output",
22 is_flag=True,
23 help="Output version information as JSON.",
24)
25def versions_command(verbose: bool, json_output: bool) -> None:
26 """Display version information for all supported tools.
28 Shows each tool's current version, minimum required version, and status.
29 Use --verbose to see installation hints for tools that don't meet requirements.
31 Args:
32 verbose: Show detailed version information including install hints.
33 json_output: Output version information as JSON.
34 """
35 tool_versions = get_all_tool_versions()
37 # JSON output mode
38 if json_output:
39 output: dict[str, dict[str, object]] = {}
40 for tool_name, version_info in sorted(tool_versions.items()):
41 output[tool_name] = {
42 "current_version": version_info.current_version,
43 "min_version": version_info.min_version,
44 "version_check_passed": version_info.version_check_passed,
45 "error_message": version_info.error_message,
46 "install_hint": version_info.install_hint,
47 }
48 click.echo(json.dumps(output, indent=2))
49 return
51 console = Console()
53 table = Table(title="Tool Versions")
54 table.add_column("Tool", style="cyan", no_wrap=True)
55 table.add_column("Current", style="yellow")
56 table.add_column("Minimum", style="green")
57 table.add_column("Status", justify="center")
59 if verbose:
60 table.add_column("Install Hint", style="dim")
62 # Sort tools by name for consistent output
63 sorted_tools = sorted(tool_versions.items())
65 for tool_name, version_info in sorted_tools:
66 current = version_info.current_version or "unknown"
67 minimum = version_info.min_version
69 if version_info.version_check_passed:
70 status = "[green]✓ PASS[/green]"
71 elif version_info.error_message:
72 status = "[red]✗ FAIL[/red]"
73 else:
74 status = "[yellow]? UNKNOWN[/yellow]"
76 row = [tool_name, current, minimum, status]
78 if verbose:
79 hint = version_info.install_hint
80 if version_info.error_message:
81 hint = f"{version_info.error_message}. {hint}"
82 row.append(hint)
84 table.add_row(*row)
86 console.print(table)
88 # Summary
89 total_tools = len(tool_versions)
90 passed_tools = sum(1 for v in tool_versions.values() if v.version_check_passed)
91 failed_tools = total_tools - passed_tools
93 if failed_tools > 0:
94 console.print(
95 f"\n[red]⚠️ {failed_tools} tool(s) do not meet "
96 f"minimum version requirements.[/red]",
97 )
98 console.print(
99 "[dim]Run with --verbose to see installation instructions.[/dim]",
100 )
101 else:
102 console.print(
103 f"\n[green]✅ All {total_tools} tools meet "
104 f"minimum version requirements.[/green]",
105 )