]> jfr.im git - yt-dlp.git/blob - devscripts/make_readme.py
[cleanup,build] Cleanup some build-related code
[yt-dlp.git] / devscripts / make_readme.py
1 #!/usr/bin/env python3
2
3 # yt-dlp --help | make_readme.py
4 # This must be run in a console of correct width
5 import re
6 import sys
7
8 README_FILE = 'README.md'
9
10 OPTIONS_START = 'General Options:'
11 OPTIONS_END = 'CONFIGURATION'
12 EPILOG_START = 'See full documentation'
13
14
15 helptext = sys.stdin.read()
16 if isinstance(helptext, bytes):
17 helptext = helptext.decode('utf-8')
18
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])
21
22 with open(README_FILE, encoding='utf-8') as f:
23 readme = f.read()
24
25 header = readme[:readme.index(f'## {OPTIONS_START}')]
26 footer = readme[readme.index(f'# {OPTIONS_END}'):]
27
28 with open(README_FILE, 'w', encoding='utf-8') as f:
29 for part in (header, options, footer):
30 f.write(part)