Discover source files in a directory. Args: base_dir: Directory to search in (relative to project root) pattern: Glob pattern for files to match (default: "*.cpp") recursive: If True, search recursively (rglob), else search only direct children (glob) Returns:
(
base_dir: str, pattern: str = "*.cpp", recursive: bool = False
)
| 11 | |
| 12 | |
| 13 | def discover_sources( |
| 14 | base_dir: str, pattern: str = "*.cpp", recursive: bool = False |
| 15 | ) -> list[str]: |
| 16 | """ |
| 17 | Discover source files in a directory. |
| 18 | |
| 19 | Args: |
| 20 | base_dir: Directory to search in (relative to project root) |
| 21 | pattern: Glob pattern for files to match (default: "*.cpp") |
| 22 | recursive: If True, search recursively (rglob), else search only direct children (glob) |
| 23 | |
| 24 | Returns: |
| 25 | List of file paths (as strings) sorted alphabetically |
| 26 | """ |
| 27 | base_path = Path(base_dir) |
| 28 | |
| 29 | if not base_path.exists(): |
| 30 | return [] |
| 31 | |
| 32 | if recursive: |
| 33 | files = sorted(base_path.rglob(pattern)) |
| 34 | else: |
| 35 | files = sorted(base_path.glob(pattern)) |
| 36 | |
| 37 | return [str(f) for f in files] |
| 38 | |
| 39 | |
| 40 | def main() -> None: |