From 588bb05bcff1935e962d705315761aa42d0af994 Mon Sep 17 00:00:00 2001 From: Martin Lehmann Date: Thu, 30 Nov 2023 18:03:54 +0100 Subject: [PATCH] feat: Add the `-r` option to the standalone HTML generator --- capella_diff_tools/report.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/capella_diff_tools/report.py b/capella_diff_tools/report.py index 5c6e892..cc67076 100644 --- a/capella_diff_tools/report.py +++ b/capella_diff_tools/report.py @@ -148,13 +148,18 @@ def generate_html(data: types.ChangeSummaryDocument) -> Markup: @click.command() -@click.argument("filename") -def main(filename): - with open(filename, encoding="locale") as f: - data = yaml.load(f, Loader=_CustomLoader) +@click.argument("filename", type=click.File("r")) +@click.option( + "-r", + "--report", + "report_file", + type=click.File("w"), + help="Write the HTML report to this file", +) +def main(filename: t.IO[str], report_file: t.IO[str]) -> None: + data = yaml.load(filename, Loader=_CustomLoader) html = generate_html(data) - with open("report.html", "w", encoding="locale") as f: - f.write(html) + report_file.write(html) if __name__ == "__main__":