slab-cli 0.1.0__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.
- slab_cli/__init__.py +0 -0
- slab_cli/banner.py +92 -0
- slab_cli/client.py +386 -0
- slab_cli/commands/__init__.py +4 -0
- slab_cli/commands/breaks.py +140 -0
- slab_cli/commands/catalog.py +84 -0
- slab_cli/commands/collection.py +676 -0
- slab_cli/commands/custom_sets.py +484 -0
- slab_cli/commands/export.py +129 -0
- slab_cli/commands/lots.py +114 -0
- slab_cli/commands/pricing.py +386 -0
- slab_cli/commands/registry.py +140 -0
- slab_cli/commands/setup.py +24 -0
- slab_cli/config.py +21 -0
- slab_cli/context.py +50 -0
- slab_cli/display.py +1187 -0
- slab_cli/flags.py +189 -0
- slab_cli/help.py +87 -0
- slab_cli/main.py +95 -0
- slab_cli/paging.py +46 -0
- slab_cli/picker.py +78 -0
- slab_cli/prompts.py +549 -0
- slab_cli/sources.py +17 -0
- slab_cli/theme.py +184 -0
- slab_cli-0.1.0.dist-info/METADATA +70 -0
- slab_cli-0.1.0.dist-info/RECORD +28 -0
- slab_cli-0.1.0.dist-info/WHEEL +4 -0
- slab_cli-0.1.0.dist-info/entry_points.txt +3 -0
slab_cli/context.py
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"""Shared runtime context for CLI commands.
|
|
2
|
+
|
|
3
|
+
Created once per invocation in main(). Commands receive it instead of
|
|
4
|
+
calling _client()/_require_collector() themselves."""
|
|
5
|
+
|
|
6
|
+
from __future__ import annotations
|
|
7
|
+
|
|
8
|
+
import sys
|
|
9
|
+
|
|
10
|
+
from .client import SlabClient
|
|
11
|
+
from .config import get_api_key, get_base_url, get_collector_uuid
|
|
12
|
+
from .display import console
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class MissingCollector(Exception):
|
|
16
|
+
"""Raised when a command needs a collector but SLAB_COLLECTOR is not set."""
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class CliContext:
|
|
20
|
+
"""Holds the API client and resolved collector UUID for a CLI session."""
|
|
21
|
+
|
|
22
|
+
def __init__(self) -> None:
|
|
23
|
+
self._client: SlabClient | None = None
|
|
24
|
+
self._collector: str | None = None
|
|
25
|
+
|
|
26
|
+
@property
|
|
27
|
+
def client(self) -> SlabClient:
|
|
28
|
+
if self._client is None:
|
|
29
|
+
self._client = SlabClient(get_base_url(), get_api_key())
|
|
30
|
+
return self._client
|
|
31
|
+
|
|
32
|
+
@property
|
|
33
|
+
def collector(self) -> str:
|
|
34
|
+
"""The active collector UUID. Resolution order: SLAB_COLLECTOR env var, then the account's
|
|
35
|
+
default collector (so a solo user only needs their API key). Raises MissingCollector if
|
|
36
|
+
neither yields one. Cached per invocation."""
|
|
37
|
+
if self._collector:
|
|
38
|
+
return self._collector
|
|
39
|
+
uuid = get_collector_uuid()
|
|
40
|
+
if not uuid:
|
|
41
|
+
# Solo zero-config: fall back to the calling account's default collector.
|
|
42
|
+
uuid = self.client.get_account_context().default_collector_uuid
|
|
43
|
+
if not uuid:
|
|
44
|
+
raise MissingCollector
|
|
45
|
+
self._collector = uuid
|
|
46
|
+
return uuid
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
# Module-level singleton — set by main() before commands run.
|
|
50
|
+
ctx = CliContext()
|