summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDennis Fink2021-12-30 20:46:39 +0100
committerDennis Fink2021-12-30 20:46:39 +0100
commit231443b908823b9c10c33ed4f378d095c2e26f91 (patch)
tree015e71934d866b1ed77af517e7ea658512394148
parent2f20aae8a6b56e0e82fc54943c04f095f616f130 (diff)
downloadpatternutils-231443b908823b9c10c33ed4f378d095c2e26f91.tar.gz
patternutils-231443b908823b9c10c33ed4f378d095c2e26f91.zip
Fail gracefully when --color is specified and pygments is not installed in patterncfg
-rw-r--r--patternutils/commands/patterncfg.py9
1 files changed, 8 insertions, 1 deletions
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])