()
| 167 | |
| 168 | |
| 169 | def main(): |
| 170 | ap = argparse.ArgumentParser(description=__doc__) |
| 171 | ap.add_argument("paths", nargs="+", help="Markdown files or directories") |
| 172 | ap.add_argument("--write", action="store_true", |
| 173 | help="Apply changes (default: dry run)") |
| 174 | ap.add_argument("--trailing-whitespace", action="store_true", |
| 175 | help="Also strip insignificant trailing whitespace " |
| 176 | "(hard-break-aware; off by default)") |
| 177 | ap.add_argument("--no-collapse-spaces", action="store_true") |
| 178 | args = ap.parse_args() |
| 179 | |
| 180 | opts = { |
| 181 | "write": args.write, |
| 182 | "trailing_ws": args.trailing_whitespace, |
| 183 | "collapse_spaces": not args.no_collapse_spaces, |
| 184 | } |
| 185 | counts = {"trailing-whitespace": 0, "collapse-spaces": 0} |
| 186 | files = expand_paths(args.paths) |
| 187 | changed = [] |
| 188 | for path in files: |
| 189 | try: |
| 190 | if process_file(path, opts, counts): |
| 191 | changed.append(path) |
| 192 | except AssertionError as exc: |
| 193 | print(f"SKIPPED (guardrail): {exc}", file=sys.stderr) |
| 194 | |
| 195 | mode = "WROTE" if args.write else "DRY RUN — would change" |
| 196 | print(f"{mode} {len(changed)} file(s) of {len(files)} scanned.") |
| 197 | print("Changes by category (files touched per transform):") |
| 198 | for cat, n in counts.items(): |
| 199 | print(f" {cat}: {n}") |
| 200 | if not args.write and changed: |
| 201 | print("\nRe-run with --write to apply. Land one batched PR; the guardrails " |
| 202 | "above guarantee front matter and code/links/words are untouched.") |
| 203 | return 0 |
| 204 | |
| 205 | |
| 206 | if __name__ == "__main__": |
no test coverage detected