Skip to content

Commit

Permalink
fix: don't overwrite output pack by default
Browse files Browse the repository at this point in the history
  • Loading branch information
vberlier committed Dec 22, 2021
1 parent 416a227 commit 0f9bd42
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,7 @@ Options:
-e, --external-files <path> Emit external files.
-p, --prefetch-urls <path> 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.
```
Expand All @@ -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
Expand Down
20 changes: 15 additions & 5 deletions lectern/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__
Expand Down Expand Up @@ -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",
Expand All @@ -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
Expand Down Expand Up @@ -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():
Expand Down

0 comments on commit 0f9bd42

Please sign in to comment.