CLI improvements

This commit is contained in:
Sina Atalay
2025-12-10 18:34:33 +03:00
parent 8563f729e8
commit 1fcf6cd7cd
3 changed files with 13 additions and 2 deletions

View File

@@ -15,13 +15,13 @@ app = typer.Typer(
rich_markup_mode="rich",
# to make `rendercv --version` work:
invoke_without_command=True,
no_args_is_help=True,
context_settings={"help_option_names": ["-h", "--help"]},
)
@app.callback()
def cli_command_no_args(
ctx: typer.Context,
version_requested: Annotated[
bool | None, typer.Option("--version", "-v", help="Show the version")
] = None,
@@ -33,6 +33,10 @@ def cli_command_no_args(
if version_requested:
print(f"RenderCV v{__version__}")
elif ctx.invoked_subcommand is None:
# No command was provided, show help
print(ctx.get_help())
raise typer.Exit()
def warn_if_new_version_is_available() -> None:

View File

@@ -154,5 +154,7 @@ def run_rendercv(
)
)
)
except OSError as e:
progress.print_user_error(RenderCVUserError(message=f"OS Error: {e}"))
except RenderCVUserValidationError as e:
progress.print_validation_errors(e.validation_errors)

View File

@@ -32,7 +32,12 @@ def run_function_if_file_changes(file_path: pathlib.Path, function: Callable):
return
with contextlib.suppress(typer.Exit):
self.function()
try:
self.function()
except Exception as e:
# This means an unhandled error occurred in the function.
# Don't surpress it
raise e
event_handler = EventHandler(function)