diff --git a/pyproject.toml b/pyproject.toml index a4c48dd..43d33c1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -16,7 +16,8 @@ requires-python = ">=3.8" keywords = ["WIS2.0", "CAP", "XML", "GeoJSON", "convert"] license = {file = "LICENSE"} dependencies = [ - + "xmltodict>=0.13.0", + "click>=8.1.7" ] dynamic = ["version"] diff --git a/src/cap2geojson/__init__.py b/src/cap2geojson/__init__.py index 61e613a..9c2d673 100644 --- a/src/cap2geojson/__init__.py +++ b/src/cap2geojson/__init__.py @@ -32,5 +32,5 @@ ) -def convert(xml: str) -> dict: +def transform(xml: str) -> dict: return to_geojson(xml) diff --git a/src/cap2geojson/cli.py b/src/cap2geojson/cli.py index e69de29..b441e38 100644 --- a/src/cap2geojson/cli.py +++ b/src/cap2geojson/cli.py @@ -0,0 +1,30 @@ +import click +import json + +from cap2geojson import __version__, transform as transform_to_geojson + + +@click.group() +@click.version_option(version=__version__) +def cli(): + """cap2geojson""" + + pass + + +@click.command() +@click.pass_context +@click.argument("cap_xml", type=click.File(mode="r", errors="ignore")) +def transform(ctx, cap_xml) -> None: + """Convert a CAP alert to GeoJSON""" + cap = cap_xml.read() + + try: + result = transform_to_geojson(cap) + click.echo(json.dumps(result, indent=2)) + except Exception as e: + click.echo(f"Error: {e}") + ctx.exit(1) + + +cli.add_command(transform)