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

1"""Versions command for displaying tool version information.""" 

2 

3import json 

4 

5import click 

6from rich.console import Console 

7from rich.table import Table 

8 

9from lintro.tools.core.version_requirements import get_all_tool_versions 

10 

11 

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. 

27 

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. 

30 

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() 

36 

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 

50 

51 console = Console() 

52 

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") 

58 

59 if verbose: 

60 table.add_column("Install Hint", style="dim") 

61 

62 # Sort tools by name for consistent output 

63 sorted_tools = sorted(tool_versions.items()) 

64 

65 for tool_name, version_info in sorted_tools: 

66 current = version_info.current_version or "unknown" 

67 minimum = version_info.min_version 

68 

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]" 

75 

76 row = [tool_name, current, minimum, status] 

77 

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) 

83 

84 table.add_row(*row) 

85 

86 console.print(table) 

87 

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 

92 

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 )