| 1 |
#!/usr/bin/env python3 |
| 2 |
import re |
| 3 |
import subprocess |
| 4 |
from pathlib import Path |
| 5 |
|
| 6 |
|
| 7 |
FILES = [ |
| 8 |
"README.md", |
| 9 |
"guide/src/local_development.md", |
| 10 |
"guide/src/tutorial.md", |
| 11 |
"guide/src/distribution.md", |
| 12 |
] |
| 13 |
|
| 14 |
|
| 15 |
def main(): |
| 16 |
root = Path(subprocess.check_output(["git", "rev-parse", "--show-toplevel"], text=True).strip()) |
| 17 |
|
| 18 |
for path in FILES: |
| 19 |
content = root.joinpath(path).read_text() |
| 20 |
|
| 21 |
matcher = re.compile(r"```\nUsage: maturin (\w+) (.*?)```", re.MULTILINE | re.DOTALL) |
| 22 |
|
| 23 |
replaces = {} |
| 24 |
for command, old in matcher.findall(content): |
| 25 |
command_output = subprocess.check_output(["cargo", "run", "--", command.lower(), "--help"], text=True) |
| 26 |
new = "Usage:" + command_output.strip().split("Usage:")[1] + "\n" |
| 27 |
# Remove trailing whitespace |
| 28 |
new = re.sub(" +\n", "\n", new) |
| 29 |
old = "Usage: maturin " + command + " " + old |
| 30 |
replaces[old] = new |
| 31 |
|
| 32 |
for old, new in replaces.items(): |
| 33 |
content = content.replace(old, new) |
| 34 |
root.joinpath(path).write_text(content) |
| 35 |
|
| 36 |
|
| 37 |
if __name__ == "__main__": |
| 38 |
main() |