Skip to content

Commit

Permalink
feat: add cli
Browse files Browse the repository at this point in the history
  • Loading branch information
RoryPTB committed Sep 3, 2024
1 parent c9a8a8d commit 2885d1a
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]

Expand Down
2 changes: 1 addition & 1 deletion src/cap2geojson/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
)


def convert(xml: str) -> dict:
def transform(xml: str) -> dict:
return to_geojson(xml)
30 changes: 30 additions & 0 deletions src/cap2geojson/cli.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 2885d1a

Please sign in to comment.