diff --git a/pyproject.toml b/pyproject.toml index a68a549..d447f55 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -34,10 +34,11 @@ sg_mbp_build = "work_helpers.sg_mbp_build:sg_mbp_build" sg_mbp_issue_ref = "work_helpers.sg_mbp_issue:sg_mbp_issue_ref" travel_pre_payment = "work_helpers.travels:fill_prepayment_form" travel_final_payment = "work_helpers.travels:final_payment" +travel_archive_note = "work_helpers.mkd2pdf:convert" xls2changelog = "work_helpers.excel2changelog:cli" xls2markdown = "work_helpers.excel2markdown:cli" xls2pylist = "work_helpers.excel2pylist:cli" -mkd_to_pdf = "work_helpers.mkd2pdf:convert" + [tool.ruff] diff --git a/work_helpers/mkd2pdf.py b/work_helpers/mkd2pdf.py index ef6cc18..6d23d3b 100644 --- a/work_helpers/mkd2pdf.py +++ b/work_helpers/mkd2pdf.py @@ -3,6 +3,8 @@ import pathlib import tempfile import subprocess +from .travels import _search_travel_notes + OSIDIAN_SEPARATOR ="---\n" @@ -54,7 +56,7 @@ def fill_fields(body, fields): return body -def convert_file(markdown) -> str: +def convert_file(markdown, *, move_original=True) -> str: path = pathlib.Path(markdown) content = path.read_text() header, body = split_header(content) @@ -74,16 +76,18 @@ def convert_file(markdown) -> str: cmd = ["typst", "compile", f"{typist}", f"{output}"] subprocess.run(cmd) - moved = get_destination() / f"Checkliste {path.name}" - subprocess.run(["mv", f"{path}", moved]) + if move_original: + moved = get_destination() / f"Checkliste {path.name}" + subprocess.run(["mv", f"{path}", moved]) + return f"{output}" @click.command() -@click.argument( - "markdowns", nargs=-1, type=click.Path(exists=True, file_okay=True, dir_okay=False) -) -def convert(markdowns): - for name in markdowns: - path = convert_file(name) - print(path) \ No newline at end of file +@click.argument("travel_numbers", nargs=-1) +@click.option("--debug", is_flag=True) +def convert(travel_numbers, debug): + for number in travel_numbers: + mkd_path = _search_travel_notes(number) + out_path = convert_file(mkd_path, move_original=(not debug)) + print(out_path) \ No newline at end of file