import re
import sys


def extract_changelog(version: str) -> str:
    tag = version.lstrip('v')

    with open('CHANGELOG.md') as f:
        content = f.read()

    pattern = rf'## \[{re.escape(tag)}\].*?\n(.*?)(?=\n## |\Z)'
    match = re.search(pattern, content, re.DOTALL)

    if match:
        return match.group(0).strip()

    return f'Release {version}'


if __name__ == '__main__':
    if len(sys.argv) < 2:
        print('Usage: python extract_changelog.py <version>', file=sys.stderr)
        sys.exit(1)

    print(extract_changelog(sys.argv[1]))