better exceptions
This commit is contained in:
parent
4580ab21a7
commit
8fffbb52a5
22
src/cli.py
22
src/cli.py
@ -7,7 +7,7 @@ import uuid
|
|||||||
import click
|
import click
|
||||||
import httpx
|
import httpx
|
||||||
from rich import pretty
|
from rich import pretty
|
||||||
from rich import print # yes, deliberately shadow `print`
|
from rich.traceback import install
|
||||||
from shiv.bootstrap import current_zipfile
|
from shiv.bootstrap import current_zipfile
|
||||||
|
|
||||||
import src
|
import src
|
||||||
@ -24,24 +24,12 @@ from src.art import BANNERS
|
|||||||
def main(ctx):
|
def main(ctx):
|
||||||
"""Launch a utility or drop into a command line REPL if no command is given."""
|
"""Launch a utility or drop into a command line REPL if no command is given."""
|
||||||
if ctx.invoked_subcommand is None:
|
if ctx.invoked_subcommand is None:
|
||||||
def print_wrapper(*args, **kwargs):
|
|
||||||
# I know this is dumb.
|
|
||||||
# https://github.com/Textualize/rich/discussions/2462
|
|
||||||
if "crop" in kwargs:
|
|
||||||
del kwargs["crop"]
|
|
||||||
print(*args, **kwargs)
|
|
||||||
|
|
||||||
banner = random.choice(BANNERS)
|
banner = random.choice(BANNERS)
|
||||||
|
|
||||||
# source of code.interact, just expanded to fit Rich in there
|
pretty.install() # type: ignore
|
||||||
console = code.InteractiveConsole(globals())
|
install() # traceback handler
|
||||||
console.print = print_wrapper
|
|
||||||
pretty.install(console) # type: ignore
|
code.interact(banner, None)
|
||||||
try:
|
|
||||||
import readline
|
|
||||||
except ImportError:
|
|
||||||
pass
|
|
||||||
console.interact(banner, None)
|
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user