rn-forge-cli 0.2.1__tar.gz → 0.2.2__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.
- {rn_forge_cli-0.2.1 → rn_forge_cli-0.2.2}/PKG-INFO +2 -2
- {rn_forge_cli-0.2.1 → rn_forge_cli-0.2.2}/pyproject.toml +2 -2
- {rn_forge_cli-0.2.1 → rn_forge_cli-0.2.2}/pyproject.toml.orig +2 -2
- {rn_forge_cli-0.2.1 → rn_forge_cli-0.2.2}/src/rn_forge/cli/app.py +48 -2
- {rn_forge_cli-0.2.1 → rn_forge_cli-0.2.2}/src/rn_forge/cli/surface.py +5 -0
- {rn_forge_cli-0.2.1 → rn_forge_cli-0.2.2}/LICENSE +0 -0
- {rn_forge_cli-0.2.1 → rn_forge_cli-0.2.2}/README.md +0 -0
- {rn_forge_cli-0.2.1 → rn_forge_cli-0.2.2}/src/rn_forge/cli/__init__.py +0 -0
- {rn_forge_cli-0.2.1 → rn_forge_cli-0.2.2}/src/rn_forge/cli/options.py +0 -0
- {rn_forge_cli-0.2.1 → rn_forge_cli-0.2.2}/src/rn_forge/cli/py.typed +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: rn-forge-cli
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.2
|
|
4
4
|
Summary: The shared command-line layer for rn-forge applications: Typer app factory, standard options, console and exit codes
|
|
5
5
|
Author: Rohit Narayanan
|
|
6
6
|
Author-email: Rohit Narayanan <rohit.nn@gmail.com>
|
|
@@ -15,7 +15,7 @@ Classifier: Programming Language :: Python :: 3.14
|
|
|
15
15
|
Classifier: Typing :: Typed
|
|
16
16
|
Requires-Dist: rn-forge-commons>=0.8.0,<0.11
|
|
17
17
|
Requires-Dist: rich>=15.0.0
|
|
18
|
-
Requires-Dist: typer>=0.
|
|
18
|
+
Requires-Dist: typer>=0.29.1
|
|
19
19
|
Requires-Dist: assertpy>=2.36.0 ; extra == 'testing'
|
|
20
20
|
Requires-Dist: pytest>=9.1.1 ; extra == 'testing'
|
|
21
21
|
Requires-Python: >=3.14
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "rn-forge-cli"
|
|
3
|
-
version = "0.2.
|
|
3
|
+
version = "0.2.2"
|
|
4
4
|
description = "The shared command-line layer for rn-forge applications: Typer app factory, standard options, console and exit codes"
|
|
5
5
|
readme = "README.md"
|
|
6
6
|
license = "MIT"
|
|
@@ -18,7 +18,7 @@ requires-python = ">=3.14"
|
|
|
18
18
|
dependencies = [
|
|
19
19
|
"rn-forge-commons>=0.8.0,<0.11",
|
|
20
20
|
"rich>=15.0.0",
|
|
21
|
-
"typer>=0.
|
|
21
|
+
"typer>=0.29.1",
|
|
22
22
|
]
|
|
23
23
|
|
|
24
24
|
[[project.authors]]
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "rn-forge-cli"
|
|
3
|
-
version = "0.2.
|
|
3
|
+
version = "0.2.2"
|
|
4
4
|
description = "The shared command-line layer for rn-forge applications: Typer app factory, standard options, console and exit codes"
|
|
5
5
|
readme = "README.md"
|
|
6
6
|
authors = [{ name = "Rohit Narayanan", email = "rohit.nn@gmail.com" }]
|
|
@@ -20,7 +20,7 @@ requires-python = ">=3.14"
|
|
|
20
20
|
dependencies = [
|
|
21
21
|
"rn-forge-commons>=0.8.0,<0.11",
|
|
22
22
|
"rich>=15.0.0",
|
|
23
|
-
"typer>=0.
|
|
23
|
+
"typer>=0.29.1",
|
|
24
24
|
]
|
|
25
25
|
|
|
26
26
|
[project.optional-dependencies]
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
5
|
+
import importlib.metadata
|
|
5
6
|
import inspect
|
|
6
7
|
import re
|
|
7
8
|
from collections.abc import Mapping, Sequence
|
|
@@ -176,6 +177,7 @@ class CliApp(typer.Typer):
|
|
|
176
177
|
help: str | None = None,
|
|
177
178
|
*,
|
|
178
179
|
default_log_level: LogLevel = LogLevel.VERBOSE,
|
|
180
|
+
version: str | None = None,
|
|
179
181
|
**typer_kwargs: Any,
|
|
180
182
|
) -> None:
|
|
181
183
|
"""Initialize the application and register its root callback.
|
|
@@ -188,6 +190,8 @@ class CliApp(typer.Typer):
|
|
|
188
190
|
``_``) as the root logger name.
|
|
189
191
|
help: The app's ``--help`` description.
|
|
190
192
|
default_log_level: Default value for ``--log-level``.
|
|
193
|
+
version: The version ``--version`` prints as ``<name> <version>``.
|
|
194
|
+
Without one the app has no ``--version`` option.
|
|
191
195
|
**typer_kwargs: Forwarded to the :class:`typer.Typer` constructor.
|
|
192
196
|
"""
|
|
193
197
|
typer_kwargs.setdefault("no_args_is_help", True)
|
|
@@ -195,7 +199,6 @@ class CliApp(typer.Typer):
|
|
|
195
199
|
super().__init__(name=name, help=help, **typer_kwargs)
|
|
196
200
|
self._logger_name = name.replace(" ", "_").lower()
|
|
197
201
|
|
|
198
|
-
@self.callback()
|
|
199
202
|
def _root(
|
|
200
203
|
ctx: typer.Context,
|
|
201
204
|
log_level: LogLevelOption = default_log_level,
|
|
@@ -219,6 +222,35 @@ class CliApp(typer.Typer):
|
|
|
219
222
|
force_reconfigure=explicit,
|
|
220
223
|
)
|
|
221
224
|
|
|
225
|
+
if version is None:
|
|
226
|
+
self.callback()(_root)
|
|
227
|
+
return
|
|
228
|
+
|
|
229
|
+
def _show_version(requested: bool) -> None:
|
|
230
|
+
if requested:
|
|
231
|
+
typer.echo(f"{name} {version}")
|
|
232
|
+
raise typer.Exit(ExitCode.OK)
|
|
233
|
+
|
|
234
|
+
# A default-value Option, not Annotated: with postponed annotations the
|
|
235
|
+
# local `_show_version` would not resolve. Eager, so it runs before the
|
|
236
|
+
# command is resolved and before `_root`.
|
|
237
|
+
@self.callback()
|
|
238
|
+
def _root_with_version(
|
|
239
|
+
ctx: typer.Context,
|
|
240
|
+
log_level: LogLevelOption = default_log_level,
|
|
241
|
+
log_file: LogFileOption = None,
|
|
242
|
+
quiet: QuietOption = False,
|
|
243
|
+
json_output: JsonOption = False,
|
|
244
|
+
show_version: bool = typer.Option(
|
|
245
|
+
False,
|
|
246
|
+
"--version",
|
|
247
|
+
callback=_show_version,
|
|
248
|
+
is_eager=True,
|
|
249
|
+
help="Show the version and exit.",
|
|
250
|
+
),
|
|
251
|
+
) -> None:
|
|
252
|
+
_root(ctx, log_level, log_file, quiet, json_output)
|
|
253
|
+
|
|
222
254
|
@classmethod
|
|
223
255
|
def from_config(
|
|
224
256
|
cls,
|
|
@@ -243,7 +275,21 @@ class CliApp(typer.Typer):
|
|
|
243
275
|
|
|
244
276
|
@classmethod
|
|
245
277
|
def from_surface(cls, surface: CliSurface, **typer_kwargs: Any) -> Self:
|
|
246
|
-
"""Build the application an already-parsed *surface* describes.
|
|
278
|
+
"""Build the application an already-parsed *surface* describes.
|
|
279
|
+
|
|
280
|
+
Raises:
|
|
281
|
+
AppException: ``surface.distribution`` is not an installed
|
|
282
|
+
distribution, or a command's target cannot be imported.
|
|
283
|
+
"""
|
|
284
|
+
if surface.distribution is not None:
|
|
285
|
+
try:
|
|
286
|
+
typer_kwargs["version"] = importlib.metadata.version(
|
|
287
|
+
surface.distribution
|
|
288
|
+
)
|
|
289
|
+
except importlib.metadata.PackageNotFoundError as error:
|
|
290
|
+
raise AppException(
|
|
291
|
+
"Distribution {!r} is not installed", surface.distribution
|
|
292
|
+
) from error
|
|
247
293
|
app = cls(
|
|
248
294
|
surface.name,
|
|
249
295
|
_escape_markup(surface.help) if surface.help else surface.help,
|
|
@@ -49,6 +49,8 @@ class CliSurface(StrictDataclassMixin):
|
|
|
49
49
|
help: The application's ``--help`` description.
|
|
50
50
|
default_log_level: The default value of ``--log-level``.
|
|
51
51
|
commands: The commands and namespaces the app exposes.
|
|
52
|
+
distribution: The installed distribution whose version ``--version``
|
|
53
|
+
prints. Without one the app has no ``--version``.
|
|
52
54
|
"""
|
|
53
55
|
|
|
54
56
|
name: str
|
|
@@ -57,10 +59,13 @@ class CliSurface(StrictDataclassMixin):
|
|
|
57
59
|
commands: tuple[CommandSurface, ...] = field(
|
|
58
60
|
default_factory=tuple[CommandSurface, ...]
|
|
59
61
|
)
|
|
62
|
+
distribution: str | None = None
|
|
60
63
|
|
|
61
64
|
def __post_init__(self) -> None:
|
|
62
65
|
if not self.name.strip():
|
|
63
66
|
raise AppException("A declared CLI needs a name")
|
|
67
|
+
if self.distribution is not None and not self.distribution.strip():
|
|
68
|
+
raise AppException("A declared CLI's distribution cannot be blank")
|
|
64
69
|
duplicates = _duplicates(command.name for command in self.commands)
|
|
65
70
|
if duplicates:
|
|
66
71
|
raise AppException("Duplicate command name(s): {}", ", ".join(duplicates))
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|