• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python3
2
3import argparse
4import re
5import pathlib
6import sys
7
8
9_STDIO = pathlib.Path("-")
10
11
12def main():
13    parser = argparse.ArgumentParser()
14    parser.add_argument("-i", "--input", type=pathlib.Path, default="CHANGELOG.md")
15    parser.add_argument("--tag", required=True)
16    parser.add_argument("-o", "--output", type=pathlib.Path, required=True)
17    args = parser.parse_args()
18
19    if args.input == _STDIO:
20        lines = sys.stdin.readlines()
21    else:
22        with args.input.open() as fh:
23            lines = fh.readlines()
24    version = args.tag.lstrip("v")
25
26    note_lines = []
27    for line in lines:
28        if line.startswith("## ") and version in line:
29            note_lines.append(line)
30        elif note_lines and line.startswith("## "):
31            break
32        elif note_lines:
33            note_lines.append(line)
34
35    notes = "".join(note_lines).strip()
36    if args.output == _STDIO:
37        print(notes)
38    else:
39        args.output.write_text(notes)
40
41
42if __name__ == "__main__":
43    main()
44