From 231443b908823b9c10c33ed4f378d095c2e26f91 Mon Sep 17 00:00:00 2001 From: Dennis Fink Date: Thu, 30 Dec 2021 20:46:39 +0100 Subject: Fail gracefully when --color is specified and pygments is not installed in patterncfg --- patternutils/commands/patterncfg.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/patternutils/commands/patterncfg.py b/patternutils/commands/patterncfg.py index 0115ed2..8f85b8f 100644 --- a/patternutils/commands/patterncfg.py +++ b/patternutils/commands/patterncfg.py @@ -136,12 +136,19 @@ def view(name: str, command: str, color: bool) -> None: click.secho("File not found!", fg="red", err=True) raise SystemExit else: - if color: + if color and has_pygments: if filename.endswith("jinja2"): lexer = DjangoLexer else: lexer = Python3Lexer text = highlight(text, lexer(), TerminalFormatter()) + elif color and not has_pygments: + click.echo( + "Pygments is not installed!. Cannot colorize output.", + fg="red", + err=True, + ) + raise SystemExit click.echo(text[:-1]) -- cgit v1.3.1