Parse arguments and run SPDX attribution on source files.
()
| 493 | |
| 494 | |
| 495 | def main(): |
| 496 | """Parse arguments and run SPDX attribution on source files.""" |
| 497 | parser = argparse.ArgumentParser( |
| 498 | description="Add SPDX attribution headers to source files" |
| 499 | ) |
| 500 | parser.add_argument( |
| 501 | "--dry-run", |
| 502 | action="store_true", |
| 503 | help="Show what would be done without making changes", |
| 504 | ) |
| 505 | parser.add_argument( |
| 506 | "--file", type=str, help="Process a specific file instead of all source files" |
| 507 | ) |
| 508 | parser.add_argument( |
| 509 | "--repo-root", type=str, default=".", help="Repository root directory" |
| 510 | ) |
| 511 | |
| 512 | args = parser.parse_args() |
| 513 | |
| 514 | # Initialize the attributor |
| 515 | attributor = SPDXAttributor(args.repo_root, dry_run=args.dry_run) |
| 516 | |
| 517 | if args.file: |
| 518 | # Process single file |
| 519 | file_path = Path(args.file) |
| 520 | if not file_path.exists(): |
| 521 | print(f"Error: File {file_path} does not exist") |
| 522 | sys.exit(1) |
| 523 | |
| 524 | attributor.process_file(file_path) |
| 525 | else: |
| 526 | # Process all source files |
| 527 | source_files = attributor.find_source_files() |
| 528 | |
| 529 | if args.dry_run: |
| 530 | print(f"Found {len(source_files)} source files to process") |
| 531 | print("\nDry run - showing what would be done:\n") |
| 532 | |
| 533 | success_count = 0 |
| 534 | for file_path in source_files: |
| 535 | if attributor.process_file(file_path): |
| 536 | success_count += 1 |
| 537 | |
| 538 | if not args.dry_run: |
| 539 | print(f"\nProcessed {success_count}/{len(source_files)} files successfully") |
| 540 | |
| 541 | |
| 542 | if __name__ == "__main__": |
no test coverage detected