()
| 105 | |
| 106 | |
| 107 | def main() -> int: |
| 108 | parser = argparse.ArgumentParser(description="Audit website sources for legacy absolute/WordPress URLs.") |
| 109 | parser.add_argument("--root", default="docs/website", help="Website root directory.") |
| 110 | parser.add_argument("--report-file", default="docs/website/reports/source-url-audit.txt", help="Report output path.") |
| 111 | parser.add_argument("--max-log", type=int, default=80, help="Max findings to print in console.") |
| 112 | parser.add_argument("--fail-on-findings", action="store_true", help="Exit non-zero if findings exist.") |
| 113 | args = parser.parse_args() |
| 114 | |
| 115 | root = Path(args.root).resolve() |
| 116 | if not root.exists(): |
| 117 | print(f"Root directory not found: {root}", file=sys.stderr) |
| 118 | return 2 |
| 119 | |
| 120 | findings = audit(root) |
| 121 | report_file = Path(args.report_file).resolve() |
| 122 | write_report(findings, report_file) |
| 123 | |
| 124 | print(f"Source URL audit findings: {len(findings)}") |
| 125 | if findings: |
| 126 | shown = min(args.max_log, len(findings)) |
| 127 | for f in findings[:shown]: |
| 128 | print(f"- {f.kind} {f.file}:{f.line_no} -> {f.url}") |
| 129 | if len(findings) > shown: |
| 130 | print(f"... {len(findings) - shown} more findings omitted") |
| 131 | print(f"Full report: {report_file}") |
| 132 | |
| 133 | return 1 if findings and args.fail_on_findings else 0 |
| 134 | |
| 135 | |
| 136 | if __name__ == "__main__": |
no test coverage detected