dhis2w-cli 0.7.0__tar.gz → 0.11.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,13 +1,13 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: dhis2w-cli
3
- Version: 0.7.0
3
+ Version: 0.11.0
4
4
  Summary: dhis2 command-line interface (Typer) — mounts plugins from dhis2w-core.
5
5
  Author: Morten Hansen
6
6
  Author-email: Morten Hansen <morten@winterop.com>
7
- Requires-Dist: dhis2w-core>=0.7.0,<0.8
7
+ Requires-Dist: dhis2w-core>=0.11.0,<0.12
8
8
  Requires-Dist: typer>=0.24
9
9
  Requires-Dist: rich>=15
10
- Requires-Dist: dhis2w-browser>=0.7.0,<0.8 ; extra == 'browser'
10
+ Requires-Dist: dhis2w-browser>=0.11.0,<0.12 ; extra == 'browser'
11
11
  Requires-Python: >=3.13
12
12
  Provides-Extra: browser
13
13
  Description-Content-Type: text/markdown
@@ -1,18 +1,18 @@
1
1
  [project]
2
2
  name = "dhis2w-cli"
3
- version = "0.7.0"
3
+ version = "0.11.0"
4
4
  description = "dhis2 command-line interface (Typer) — mounts plugins from dhis2w-core."
5
5
  readme = "README.md"
6
6
  authors = [{ name = "Morten Hansen", email = "morten@winterop.com" }]
7
7
  requires-python = ">=3.13"
8
8
  dependencies = [
9
- "dhis2w-core>=0.7.0,<0.8",
9
+ "dhis2w-core>=0.11.0,<0.12",
10
10
  "typer>=0.24",
11
11
  "rich>=15",
12
12
  ]
13
13
 
14
14
  [project.optional-dependencies]
15
- browser = ["dhis2w-browser>=0.7.0,<0.8"]
15
+ browser = ["dhis2w-browser>=0.11.0,<0.12"]
16
16
 
17
17
  [project.scripts]
18
18
  dhis2 = "dhis2w_cli.main:main"
@@ -4,16 +4,52 @@ from __future__ import annotations
4
4
 
5
5
  import logging
6
6
  import os
7
+ from importlib.metadata import PackageNotFoundError, version
7
8
  from typing import Annotated
8
9
 
9
10
  import typer
10
11
  from dhis2w_core.cli_errors import run_app
11
12
  from dhis2w_core.cli_output import JSON_OUTPUT
12
- from dhis2w_core.plugin import discover_plugins
13
+ from dhis2w_core.plugin import DEFAULT_VERSION_KEY, discover_plugins, resolve_startup_version
13
14
  from dhis2w_core.rich_console import STDERR_CONSOLE
14
15
  from rich.logging import RichHandler
15
16
 
16
17
 
18
+ def _version_banner() -> str:
19
+ """Multi-line banner shown for `dhis2 --version` — package version + active plugin tree.
20
+
21
+ Surfaces which plugin tree (`v41` / `v42` / `v43`) the CLI booted with
22
+ and where that came from in the resolution chain (`profile.version` →
23
+ `DHIS2_VERSION` env → default). Helps debug "which DHIS2 major is
24
+ this CLI talking to" without reading the profile by hand.
25
+ """
26
+ try:
27
+ pkg_version = version("dhis2w-cli")
28
+ except PackageNotFoundError:
29
+ pkg_version = "unknown"
30
+ active = resolve_startup_version()
31
+ env_version = os.environ.get("DHIS2_VERSION", "").strip()
32
+ if (
33
+ env_version in {"41", "42", "43"}
34
+ and f"v{env_version}" == active
35
+ or env_version in {"v41", "v42", "v43"}
36
+ and env_version == active
37
+ ):
38
+ source = f"DHIS2_VERSION={env_version!r} env"
39
+ elif active == DEFAULT_VERSION_KEY:
40
+ source = "default (no profile.version, no DHIS2_VERSION env)"
41
+ else:
42
+ source = "profile.version"
43
+ return f"dhis2 {pkg_version} (plugin tree: {active} — {source})"
44
+
45
+
46
+ def _version_callback(value: bool) -> None:
47
+ """Eager `--version` callback — print the banner and exit."""
48
+ if value:
49
+ typer.echo(_version_banner())
50
+ raise typer.Exit(0)
51
+
52
+
17
53
  def _enable_debug_logging() -> None:
18
54
  """Turn on dhis2w-client HTTP traces + dhis2w-core debug logs on stderr.
19
55
 
@@ -78,6 +114,16 @@ def build_app() -> typer.Typer:
78
114
  help="Emit raw JSON to stdout instead of Rich tables (uniform across all commands).",
79
115
  ),
80
116
  ] = False,
117
+ _version: Annotated[
118
+ bool,
119
+ typer.Option(
120
+ "--version",
121
+ "-V",
122
+ help="Print the CLI version + active plugin tree and exit.",
123
+ callback=_version_callback,
124
+ is_eager=True,
125
+ ),
126
+ ] = False,
81
127
  ) -> None:
82
128
  """Set the active DHIS2 profile + optional debug logging + output mode for this invocation."""
83
129
  if profile:
@@ -89,7 +135,7 @@ def build_app() -> typer.Typer:
89
135
  # invocation must not leak into the next one.
90
136
  JSON_OUTPUT.set(json_)
91
137
 
92
- for plugin in discover_plugins():
138
+ for plugin in discover_plugins(resolve_startup_version()):
93
139
  plugin.register_cli(app)
94
140
  return app
95
141
 
File without changes