chore(lib): enhance error message for --folder (#462)

Closes #461.
This commit is contained in:
Jérome Eertmans
2024-08-07 12:05:53 +02:00
committed by GitHub
parent f707b6cd0c
commit 6572dc3e21
2 changed files with 14 additions and 1 deletions

View File

@ -27,6 +27,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
[#447](https://github.com/jeertmans/manim-slides/pull/447)
- Improved issue templates.
[#456](https://github.com/jeertmans/manim-slides/pull/456)
- Enhancer the error message when the slides folder does not exist.
[#462](https://github.com/jeertmans/manim-slides/pull/462)
(unreleased-fixed)=
### Fixed

View File

@ -70,11 +70,22 @@ def verbosity_option(function: F) -> F:
def folder_path_option(function: F) -> F:
"""Wrap a function to add folder path option."""
def callback(ctx: Context, param: Parameter, value: Path) -> Path:
if not value.exists():
raise click.UsageError(
f"Invalid value for '--folder': Directory '{value}' does not exist. "
"Did you render the animations first?",
ctx=ctx,
)
return value
wrapper: Wrapper = click.option(
"--folder",
metavar="DIRECTORY",
default=FOLDER_PATH,
type=click.Path(exists=True, file_okay=False, path_type=Path),
type=click.Path(file_okay=False, path_type=Path),
callback=callback,
help="Set slides folder.",
show_default=True,
)