pcf-toolkit 0.2.5__py3-none-any.whl

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.
@@ -0,0 +1,62 @@
1
+ """Shared CLI utilities for rich output."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from collections.abc import Iterable
6
+
7
+ try:
8
+ from rich.console import Console
9
+ from rich.table import Table
10
+ except Exception: # pragma: no cover - fallback if rich isn't available
11
+ Console = None
12
+ Table = None
13
+
14
+
15
+ def rich_console(stderr: bool = False):
16
+ """Returns a Rich console if available, otherwise None.
17
+
18
+ Args:
19
+ stderr: If True, creates a console that writes to stderr.
20
+
21
+ Returns:
22
+ A Rich Console instance if Rich is available, otherwise None.
23
+ """
24
+ if Console is None:
25
+ return None
26
+ return Console(stderr=stderr)
27
+
28
+
29
+ def render_validation_table(
30
+ errors: Iterable[dict],
31
+ *,
32
+ title: str,
33
+ stderr: bool = True,
34
+ ) -> bool:
35
+ """Renders a validation error table using Rich.
36
+
37
+ Args:
38
+ errors: Iterable of validation error dictionaries.
39
+ title: Title for the error table.
40
+ stderr: If True, writes to stderr instead of stdout.
41
+
42
+ Returns:
43
+ True if the table was rendered successfully, False otherwise.
44
+ """
45
+ if Table is None:
46
+ return False
47
+
48
+ console = rich_console(stderr=stderr)
49
+ if console is None:
50
+ return False
51
+
52
+ table = Table(title=title, show_lines=False)
53
+ table.add_column("Location", style="bold")
54
+ table.add_column("Message")
55
+ table.add_column("Type", style="dim")
56
+ for error in errors:
57
+ loc = ".".join(str(part) for part in error.get("loc", [])) or "<root>"
58
+ msg = error.get("msg", "Invalid value")
59
+ err_type = error.get("type", "validation_error")
60
+ table.add_row(loc, msg, err_type)
61
+ console.print(table)
62
+ return True
@@ -0,0 +1 @@
1
+ """Package data for schema snapshots."""