]>
Commit | Line | Data |
---|---|---|
cc52de43 | 1 | #!/usr/bin/env python3 |
2 | ||
3 | # yt-dlp --help | make_readme.py | |
4 | # This must be run in a console of correct width | |
4bb028f4 | 5 | import re |
f8271158 | 6 | import sys |
4bb028f4 | 7 | |
682407f2 | 8 | README_FILE = 'README.md' |
4bb028f4 | 9 | |
19a03940 | 10 | OPTIONS_START = 'General Options:' |
11 | OPTIONS_END = 'CONFIGURATION' | |
12 | EPILOG_START = 'See full documentation' | |
13 | ||
14 | ||
15 | helptext = sys.stdin.read() | |
49f2bf76 PH |
16 | if isinstance(helptext, bytes): |
17 | helptext = helptext.decode('utf-8') | |
18 | ||
19a03940 | 19 | start, end = helptext.index(f'\n {OPTIONS_START}'), helptext.index(f'\n{EPILOG_START}') |
20 | options = re.sub(r'(?m)^ (\w.+)$', r'## \1', helptext[start + 1: end + 1]) | |
4bb028f4 | 21 | |
19a03940 | 22 | with open(README_FILE, encoding='utf-8') as f: |
23 | readme = f.read() | |
4bb028f4 | 24 | |
19a03940 | 25 | header = readme[:readme.index(f'## {OPTIONS_START}')] |
26 | footer = readme[readme.index(f'# {OPTIONS_END}'):] | |
4bb028f4 | 27 | |
86e5f3ed | 28 | with open(README_FILE, 'w', encoding='utf-8') as f: |
19a03940 | 29 | for part in (header, options, footer): |
30 | f.write(part) |