]> jfr.im git - yt-dlp.git/blame - devscripts/make_readme.py
[cleanup] Misc cleanup and refactor (#2173)
[yt-dlp.git] / devscripts / make_readme.py
CommitLineData
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 5import re
f8271158 6import sys
4bb028f4 7
682407f2 8README_FILE = 'README.md'
4bb028f4 9
19a03940 10OPTIONS_START = 'General Options:'
11OPTIONS_END = 'CONFIGURATION'
12EPILOG_START = 'See full documentation'
13
14
15helptext = sys.stdin.read()
49f2bf76
PH
16if isinstance(helptext, bytes):
17 helptext = helptext.decode('utf-8')
18
19a03940 19start, end = helptext.index(f'\n {OPTIONS_START}'), helptext.index(f'\n{EPILOG_START}')
20options = re.sub(r'(?m)^ (\w.+)$', r'## \1', helptext[start + 1: end + 1])
4bb028f4 21
19a03940 22with open(README_FILE, encoding='utf-8') as f:
23 readme = f.read()
4bb028f4 24
19a03940 25header = readme[:readme.index(f'## {OPTIONS_START}')]
26footer = readme[readme.index(f'# {OPTIONS_END}'):]
4bb028f4 27
86e5f3ed 28with open(README_FILE, 'w', encoding='utf-8') as f:
19a03940 29 for part in (header, options, footer):
30 f.write(part)