MCPcopy Create free account
hub / github.com/ClickHouse/ai-sdk-cpp / main

Function main

scripts/format.py:64–104  ·  view source on GitHub ↗

Format all C++ source files using clang-format.

(check: bool)

Source from the content-addressed store, hash-verified

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

Callers 1

format.pyFile · 0.70

Calls 3

check_file_formatFunction · 0.85
format_fileFunction · 0.85
find_cpp_filesFunction · 0.70

Tested by

no test coverage detected