(
file: list[str] | None, directory: str, exit_on_error: bool, check: bool
)
| 336 | |
| 337 | |
| 338 | def main( |
| 339 | file: list[str] | None, directory: str, exit_on_error: bool, check: bool |
| 340 | ): |
| 341 | if file is not None: |
| 342 | result = [format_file(Path(f), exit_on_error, check) for f in file] |
| 343 | else: |
| 344 | result = [ |
| 345 | format_file(doc, exit_on_error, check) |
| 346 | for doc in iter_files(directory) |
| 347 | ] |
| 348 | |
| 349 | if check: |
| 350 | formatting_error_counts = [e for _, e in result if e] |
| 351 | to_reformat = len([b for b, _ in result if not b]) |
| 352 | |
| 353 | if not to_reformat and not formatting_error_counts: |
| 354 | print("All files are correctly formatted") |
| 355 | exit(0) |
| 356 | else: |
| 357 | print( |
| 358 | f"{to_reformat} file(s) would be reformatted;", |
| 359 | ( |
| 360 | ( |
| 361 | f"{sum(formatting_error_counts)} formatting errors " |
| 362 | f"reported in {len(formatting_error_counts)} files" |
| 363 | ) |
| 364 | if formatting_error_counts |
| 365 | else "no formatting errors reported" |
| 366 | ), |
| 367 | ) |
| 368 | |
| 369 | exit(1) |
| 370 | |
| 371 | |
| 372 | if __name__ == "__main__": |
no test coverage detected