|
25 | 25 | from cli_core_yo.app import create_app |
26 | 26 | from cli_core_yo.runtime import _reset, initialize |
27 | 27 | from cli_core_yo.spec import CliSpec, XdgSpec |
| 28 | +from daylily_ec import versioning |
28 | 29 |
|
29 | 30 | # ── App specification ──────────────────────────────────────────────────────── |
30 | 31 |
|
|
42 | 43 | app = create_app(spec) |
43 | 44 | pricing_app = typer.Typer(help="Spot pricing inspection helpers.") |
44 | 45 | app.add_typer(pricing_app, name="pricing") |
| 46 | +app.registered_commands[:] = [ |
| 47 | + cmd for cmd in app.registered_commands if cmd.name not in {"version", "info"} |
| 48 | +] |
| 49 | + |
| 50 | + |
| 51 | +def _installed_dist_version(dist_name: str) -> str: |
| 52 | + try: |
| 53 | + from importlib.metadata import version |
| 54 | + |
| 55 | + return version(dist_name) |
| 56 | + except Exception: |
| 57 | + return "unknown" |
| 58 | + |
| 59 | + |
| 60 | +@app.command("version") |
| 61 | +def version_command( |
| 62 | + json: bool = typer.Option(False, "--json", "-j", help="Output as JSON."), |
| 63 | +) -> None: |
| 64 | + """Show version.""" |
| 65 | + version = versioning.get_version() |
| 66 | + if json: |
| 67 | + output.emit_json({"app": spec.app_display_name, "version": version}) |
| 68 | + else: |
| 69 | + output.print_text(f"{spec.app_display_name} [cyan]{version}[/cyan]") |
| 70 | + |
| 71 | + |
| 72 | +@app.command("info") |
| 73 | +def info_command( |
| 74 | + json: bool = typer.Option(False, "--json", "-j", help="Output as JSON."), |
| 75 | +) -> None: |
| 76 | + """Show system info.""" |
| 77 | + xdg_paths = app._cli_core_yo_xdg_paths # type: ignore[attr-defined] |
| 78 | + rows: list[tuple[str, str]] = [ |
| 79 | + ("Version", versioning.get_version()), |
| 80 | + ("Python", sys.version.split()[0]), |
| 81 | + ("Config Dir", str(xdg_paths.config)), |
| 82 | + ("Data Dir", str(xdg_paths.data)), |
| 83 | + ("State Dir", str(xdg_paths.state)), |
| 84 | + ("Cache Dir", str(xdg_paths.cache)), |
| 85 | + ("CLI Core", _installed_dist_version("cli-core-yo")), |
| 86 | + ] |
| 87 | + for hook in spec.info_hooks: |
| 88 | + rows.extend(hook()) |
| 89 | + |
| 90 | + if json: |
| 91 | + output.emit_json({key: value for key, value in rows}) |
| 92 | + return |
| 93 | + |
| 94 | + output.heading(f"{spec.app_display_name} Info") |
| 95 | + max_key = max(len(key) for key, _ in rows) |
| 96 | + for key, value in rows: |
| 97 | + output.print_text(f" {key:<{max_key}} {value}") |
45 | 98 |
|
46 | 99 |
|
47 | 100 | # ── Root callback (global options) ─────────────────────────────────────────── |
|
0 commit comments