import argparse import re import sys def parse_changelog(file_path, version, title_only, extra_spaces, separators): try: with open(file_path, 'r') as f: changelog = f.read() except FileNotFoundError: print(f"Error: File '{file_path}' not found.") sys.exit(1) # Regex to match the version block and stop at the next version or any line with square brackets version_pattern = re.compile(rf"## \[{version}\] - (\d{{4}}-\d{{2}}-\d{{2}})\n(.*?)(?=## \[|\[Unreleased\]:|\[\d+\.\d+\.\d+\]:|$)", re.DOTALL) match = version_pattern.search(changelog) if not match: print(f"Version {version} not found.") return date, content = match.groups() if title_only: print(f"Version {version} - {date}") else: if separators is not None: content = re.sub(r'^(###.*?)$', '_' * separators + r'\n\1', content, flags=re.MULTILINE) cleaned_content = re.sub(r'### ', '', content) # Remove ### if extra_spaces: cleaned_content = re.sub(r'(?