Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ dependencies = [
"sparqlwrapper~=2.0",
]

[project.optional-dependencies]
highlights = ["pygments ~= 2.17"]

[project.entry-points]
"xnat.cli" = { img2catalog = "img2catalog.cli_app:cli_click" }

Expand Down
19 changes: 18 additions & 1 deletion src/img2catalog/cli_app.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,24 @@
import logging
import sys
from pathlib import Path

import click
import xnat
from click_option_group import MutuallyExclusiveOptionGroup, optgroup
from rdflib import URIRef

if sys.stdout.isatty():
try:
from pygments import highlight
from pygments.formatters import TerminalFormatter
from pygments.lexers import TurtleLexer

syntax_highlight = True
except ImportError:
syntax_highlight = False
else:
syntax_highlight = False

from img2catalog import log
from img2catalog.__about__ import __version__
from img2catalog.configmanager import load_img2catalog_configuration
Expand Down Expand Up @@ -205,7 +218,11 @@ def output_dcat(ctx: click.Context, output: click.Path, format: str):

else:
logger.debug("Sending output to stdout")
print(g.serialize(format=format))
serialized_output = g.serialize(format=format)
if format == "turtle" and syntax_highlight:
click.echo(highlight(serialized_output, TurtleLexer(), TerminalFormatter(bg="dark")))
else:
print(serialized_output)


@click.option("-f", "--fdp", envvar=FDP_SERVER_ENV, type=str, required=True, help="URL of FDP to push datasets to")
Expand Down