Skip to content

Commit 96e5cb3

Browse files
committed
colorize cli
1 parent f8d9ab8 commit 96e5cb3

1 file changed

Lines changed: 58 additions & 19 deletions

File tree

src/transformez/cli.py

Lines changed: 58 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,38 +13,75 @@
1313

1414
import sys
1515
import click
16-
import logging
17-
from transformez import api
1816

19-
# logger = logging.getLogger(__name__)
17+
from fetchez.utils import FetchezMainGroup, FetchezMainCommand
18+
from fetchez.cli import setup_logging
19+
20+
from transformez import api
2021

2122

22-
class AliasedGroup(click.Group):
23+
class TransformezMainGroup(FetchezMainGroup):
2324
"""A custom Click Group that handles deprecated aliases."""
2425

2526
def get_command(self, ctx, cmd_name):
2627
if cmd_name == "run":
2728
click.secho(
2829
" DEPRECATION WARNING: 'transformez run' is deprecated and will be removed in a future release.\n"
29-
"Please use 'transformez grid' to generate shift grids instead.",
30+
"Please use 'transformez grid' to generate shift grids or 'transformez raster' to shift a raster.",
3031
fg="yellow",
3132
err=True,
3233
)
3334
return click.Group.get_command(self, ctx, "run")
3435

3536
return click.Group.get_command(self, ctx, cmd_name)
3637

37-
38-
@click.group(name="transform", cls=AliasedGroup)
38+
# def format_commands(self, ctx, formatter):
39+
# commands = []
40+
# for subcommand in self.list_commands(ctx):
41+
# cmd = self.get_command(ctx, subcommand)
42+
# if cmd is None or cmd.hidden:
43+
# continue
44+
# commands.append((subcommand, cmd))
45+
46+
# if not commands:
47+
# return
48+
49+
# categories = {
50+
# f"{colorize('Execution', YELLOW)}": ["run", "grid", "raster"],
51+
# f"{colorize('Discovery & Management', YELLOW)}": [
52+
# "list",
53+
# "htdp",
54+
# "vdatum",
55+
# ],
56+
# }
57+
58+
# for cat_name, cmd_names in categories.items():
59+
# with formatter.section(cat_name):
60+
# cat_cmds = [
61+
# (f"{colorize(name, BOLD):<17}", cmd.get_short_help_str(limit=80))
62+
# for name, cmd in commands
63+
# if name in cmd_names
64+
# ]
65+
# formatter.write_dl(cat_cmds)
66+
67+
68+
@click.group(
69+
name="transform",
70+
cls=TransformezMainGroup,
71+
fetchez_commands=["run", "grid", "raster", "list", "htdp", "vdatum"],
72+
)
3973
@click.version_option(package_name="transformez")
40-
def transformez_cli():
74+
@click.option("--verbose", is_flag=True, help="Enable verbose debug logging.")
75+
@click.option("--quiet", is_flag=True, help="Suppress non-error output.")
76+
def transformez_cli(verbose, quiet):
4177
"""Apply vertical datum transformations and generate shift grids."""
4278

43-
logging.basicConfig(level=logging.INFO, format="[%(levelname)s] %(message)s")
79+
setup_logging(name="transformez", quiet=quiet, verbose=verbose)
80+
# logging.basicConfig(level=logging.INFO, format="[%(levelname)s] %(message)s")
4481
pass
4582

4683

47-
@transformez_cli.command("run")
84+
@transformez_cli.command("run", cls=FetchezMainCommand)
4885
@click.argument("input_file", required=False)
4986
@click.option(
5087
"-R", "--region", help="Bounding box or location string (if no input file)."
@@ -160,7 +197,7 @@ def transform_run(
160197
# =====================================================================
161198
# GENERATE SHIFT GRID
162199
# =====================================================================
163-
@transformez_cli.command("grid")
200+
@transformez_cli.command("grid", cls=FetchezMainCommand)
164201
@click.option("-R", "--region", required=True, help="Bounding box or location string.")
165202
@click.option("-E", "--increment", required=True, help="Resolution (e.g., 1s, 30m).")
166203
@click.option(
@@ -232,7 +269,7 @@ def transform_grid(
232269
# =====================================================================
233270
# TRANSFORM EXISTING RASTER (DEM)
234271
# =====================================================================
235-
@transformez_cli.command("raster")
272+
@transformez_cli.command("raster", cls=FetchezMainCommand)
236273
@click.argument("input_file", type=click.Path(exists=True))
237274
@click.option("-I", "--input-datum", required=True, help="Source Datum (e.g., 'mllw').")
238275
@click.option(
@@ -269,7 +306,7 @@ def transform_raster(
269306
decay_pixels,
270307
use_stations,
271308
):
272-
"""Apply a vertical datum shift (and optional unit conversion) to an existing DEM."""
309+
"""Apply a vertical datum shift to an existing DEM."""
273310

274311
click.secho(f"Transforming raster: {input_file}", fg="cyan", bold=True)
275312
click.echo(f" Shift: {input_datum}{output_datum}")
@@ -294,7 +331,7 @@ def transform_raster(
294331

295332

296333
# --- LIST DATUMS, ETC. ---
297-
@transformez_cli.command("list")
334+
@transformez_cli.command("list", cls=FetchezMainCommand)
298335
def transform_list():
299336
"""List all supported vertical datums, EPSG codes, and geoids."""
300337
try:
@@ -350,14 +387,14 @@ def transform_list():
350387

351388

352389
# --- HTDP CLI GROUP ---
353-
@transformez_cli.group("htdp")
390+
@transformez_cli.group(cls=FetchezMainGroup, name="htdp", fetchez_commands=["install"])
354391
def htdp_group():
355392
"""Manage and run NGS HTDP (Horizontal Time-Dependent Positioning)."""
356393

357394
pass
358395

359396

360-
@htdp_group.command("install")
397+
@htdp_group.command("install", cls=FetchezMainCommand)
361398
def install_htdp():
362399
"""Downloads and compiles the HTDP executable."""
363400

@@ -367,7 +404,9 @@ def install_htdp():
367404

368405

369406
# --- VDATUM CLI GROUP ---
370-
@transformez_cli.group("vdatum")
407+
@transformez_cli.group(
408+
cls=FetchezMainGroup, name="vdatum", fetchez_commands=["install", "run"]
409+
)
371410
def vdatum_group():
372411
"""Manage and run the NOAA VDatum Java engine."""
373412

@@ -383,7 +422,7 @@ def install_vdatum():
383422
install_vdatum_jar()
384423

385424

386-
@vdatum_group.command("run")
425+
@vdatum_group.command("run", cls=FetchezMainCommand)
387426
@click.argument("input_file", type=click.Path(exists=True))
388427
@click.argument("output_file", type=click.Path())
389428
@click.option(
@@ -412,7 +451,7 @@ def run_vdatum_cli(
412451
).run_vdatum(input_file)
413452

414453

415-
@vdatum_group.command("list")
454+
@vdatum_group.command("list", cls=FetchezMainCommand)
416455
def vdatum_list():
417456
"""List the supported vdatum grids"""
418457

0 commit comments

Comments
 (0)