Skip to content

Commit

Permalink
Show a clearer error when click-repl is missing
Browse files Browse the repository at this point in the history
By conditionally registering the repl handler, if the optional
dependency is missing it looks like the command doesn't exist. Ensure
that a somewhat clearer error message is used instead.
  • Loading branch information
WhyNotHugo committed Mar 28, 2024
1 parent a9e7e7e commit 75e80c2
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions todoman/cli.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from __future__ import annotations

import contextlib
import functools
import glob
import locale
Expand Down Expand Up @@ -336,11 +335,16 @@ def invoke_command(click_ctx, command):
click_ctx.invoke(cli.commands[name], *args, **opts)


with contextlib.suppress(ImportError):
import click_repl
@cli.command()
@click.pass_context
def repl(ctx):
try:
from click_repl import repl

click_repl.register_repl(cli)
click_repl.register_repl(cli, name="shell")
repl(ctx)
except ImportError as e:
click.echo(e)
sys.exit(-1)


@cli.command()
Expand Down

0 comments on commit 75e80c2

Please sign in to comment.