From 0f9bd42065fd899ed1dbc2c3a9033ea51c06ebdf Mon Sep 17 00:00:00 2001 From: Valentin Berlier Date: Thu, 23 Dec 2021 00:20:44 +0100 Subject: [PATCH] fix: don't overwrite output pack by default --- README.md | 7 +++++++ lectern/cli.py | 20 +++++++++++++++----- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index be6ed58..9f4ee0e 100644 --- a/README.md +++ b/README.md @@ -368,6 +368,7 @@ Options: -e, --external-files Emit external files. -p, --prefetch-urls Prefetch markdown links. -f, --flat Use the flat markdown format. + -o, --overwrite Overwrite the output pack. -v, --version Show the version and exit. -h, --help Show this message and exit. ``` @@ -389,6 +390,12 @@ $ lectern demo.md -r demo_resource_pack $ lectern demo.md -d demo_data_pack -r demo_resource_pack ``` +If you want to overwrite an existing data pack or resource pack you need to specify the `-o/--overwrite` option explicitly. + +```bash +$ lectern demo.md --overwrite --data-pack demo_data_pack +``` + You can also convert a combination of data packs and resource packs into a single markdown file. ```bash diff --git a/lectern/cli.py b/lectern/cli.py index 3def7d2..7c4c741 100644 --- a/lectern/cli.py +++ b/lectern/cli.py @@ -7,7 +7,7 @@ from typing import Any, Optional, Tuple import click -from beet import run_beet +from beet import ErrorMessage, run_beet from beet.toolchain.cli import error_handler from lectern import __version__ @@ -53,6 +53,12 @@ def echo(*args: Any, **kwargs: Any): is_flag=True, help="Use the flat markdown format.", ) +@click.option( + "-o", + "--overwrite", + is_flag=True, + help="Overwrite the output pack.", +) @click.version_option( __version__, "-v", @@ -68,6 +74,7 @@ def lectern( external_files: Optional[str], prefetch_urls: Optional[str], flat: bool, + overwrite: bool, ): """Literate Minecraft data packs and resource packs.""" config: Any @@ -113,10 +120,13 @@ def lectern( } with run_beet(config) as beet_ctx: - if data_pack: - beet_ctx.data.save(path=data_pack, overwrite=True) - if resource_pack: - beet_ctx.assets.save(path=resource_pack, overwrite=True) + try: + if data_pack: + beet_ctx.data.save(path=data_pack, overwrite=overwrite) + if resource_pack: + beet_ctx.assets.save(path=resource_pack, overwrite=overwrite) + except FileExistsError as exc: + raise ErrorMessage(f"{exc} (run again with --overwrite)") from exc def main():