Format all C++ source files using clang-format.
(check: bool)
| 62 | @click.command() |
| 63 | @click.option("--check", is_flag=True, help="Check formatting without modifying files") |
| 64 | def main(check: bool): |
| 65 | """Format all C++ source files using clang-format.""" |
| 66 | # Check if clang-format is installed |
| 67 | if not shutil.which("clang-format"): |
| 68 | console.print("[red]Error: clang-format is not installed.[/red]") |
| 69 | console.print("Install it with: brew install clang-format (macOS) or apt-get install clang-format (Ubuntu)") |
| 70 | sys.exit(1) |
| 71 | |
| 72 | # Find all C++ files |
| 73 | files = find_cpp_files() |
| 74 | |
| 75 | if not files: |
| 76 | console.print("[yellow]No C++ files found[/yellow]") |
| 77 | return |
| 78 | |
| 79 | if check: |
| 80 | console.print(f"[blue]Checking code formatting for {len(files)} files...[/blue]\n") |
| 81 | |
| 82 | needs_format = [] |
| 83 | for file in track(files, description="Checking files...", console=console): |
| 84 | if not check_file_format(file): |
| 85 | needs_format.append(file) |
| 86 | console.print(f"[red]✗[/red] {file.relative_to(file.parent.parent)}") |
| 87 | |
| 88 | if not needs_format: |
| 89 | console.print("\n[green]✅ All files are properly formatted[/green]") |
| 90 | sys.exit(0) |
| 91 | else: |
| 92 | console.print(f"\n[red]❌ {len(needs_format)} files need formatting:[/red]") |
| 93 | for file in needs_format: |
| 94 | console.print(f" • {file.relative_to(file.parent.parent)}") |
| 95 | console.print("\n[yellow]Run 'uv run scripts/format.py' to fix them.[/yellow]") |
| 96 | sys.exit(1) |
| 97 | else: |
| 98 | console.print(f"[blue]Formatting {len(files)} C++ files...[/blue]\n") |
| 99 | |
| 100 | for file in track(files, description="Formatting files...", console=console): |
| 101 | format_file(file) |
| 102 | console.print(f"[green]✓[/green] {file.name}") |
| 103 | |
| 104 | console.print("\n[green]✅ All files have been formatted[/green]") |
| 105 | |
| 106 | |
| 107 | if __name__ == "__main__": |
no test coverage detected