slab-cli 0.3.0__tar.gz → 0.4.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.
- {slab_cli-0.3.0 → slab_cli-0.4.0}/PKG-INFO +1 -1
- {slab_cli-0.3.0 → slab_cli-0.4.0}/pyproject.toml +1 -1
- slab_cli-0.4.0/src/slab_cli/commands/setup.py +51 -0
- {slab_cli-0.3.0 → slab_cli-0.4.0}/src/slab_cli/context.py +4 -15
- {slab_cli-0.3.0 → slab_cli-0.4.0}/src/slab_cli/main.py +19 -1
- slab_cli-0.3.0/src/slab_cli/commands/setup.py +0 -23
- {slab_cli-0.3.0 → slab_cli-0.4.0}/README.md +0 -0
- {slab_cli-0.3.0 → slab_cli-0.4.0}/src/slab_cli/__init__.py +0 -0
- {slab_cli-0.3.0 → slab_cli-0.4.0}/src/slab_cli/banner.py +0 -0
- {slab_cli-0.3.0 → slab_cli-0.4.0}/src/slab_cli/client.py +0 -0
- {slab_cli-0.3.0 → slab_cli-0.4.0}/src/slab_cli/commands/__init__.py +0 -0
- {slab_cli-0.3.0 → slab_cli-0.4.0}/src/slab_cli/commands/breaks.py +0 -0
- {slab_cli-0.3.0 → slab_cli-0.4.0}/src/slab_cli/commands/catalog.py +0 -0
- {slab_cli-0.3.0 → slab_cli-0.4.0}/src/slab_cli/commands/collection.py +0 -0
- {slab_cli-0.3.0 → slab_cli-0.4.0}/src/slab_cli/commands/custom_sets.py +0 -0
- {slab_cli-0.3.0 → slab_cli-0.4.0}/src/slab_cli/commands/export.py +0 -0
- {slab_cli-0.3.0 → slab_cli-0.4.0}/src/slab_cli/commands/lots.py +0 -0
- {slab_cli-0.3.0 → slab_cli-0.4.0}/src/slab_cli/commands/pricing.py +0 -0
- {slab_cli-0.3.0 → slab_cli-0.4.0}/src/slab_cli/commands/registry.py +0 -0
- {slab_cli-0.3.0 → slab_cli-0.4.0}/src/slab_cli/config.py +0 -0
- {slab_cli-0.3.0 → slab_cli-0.4.0}/src/slab_cli/display.py +0 -0
- {slab_cli-0.3.0 → slab_cli-0.4.0}/src/slab_cli/flags.py +0 -0
- {slab_cli-0.3.0 → slab_cli-0.4.0}/src/slab_cli/help.py +0 -0
- {slab_cli-0.3.0 → slab_cli-0.4.0}/src/slab_cli/paging.py +0 -0
- {slab_cli-0.3.0 → slab_cli-0.4.0}/src/slab_cli/picker.py +0 -0
- {slab_cli-0.3.0 → slab_cli-0.4.0}/src/slab_cli/prompts.py +0 -0
- {slab_cli-0.3.0 → slab_cli-0.4.0}/src/slab_cli/sources.py +0 -0
- {slab_cli-0.3.0 → slab_cli-0.4.0}/src/slab_cli/theme.py +0 -0
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"""Setup commands — check identity.
|
|
2
|
+
|
|
3
|
+
Collectors are NOT created here. Your account and its collector are provisioned when you sign up
|
|
4
|
+
in the portal; the CLI just consumes the API key and collector UUID you get there. SLAB_COLLECTOR
|
|
5
|
+
is required and explicit — the CLI does not guess a collector from the account, so you must set it
|
|
6
|
+
to the UUID you copy from the portal (Settings).
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from __future__ import annotations
|
|
10
|
+
|
|
11
|
+
from slab_schemas.account import MeOut
|
|
12
|
+
|
|
13
|
+
from ..config import get_collector_uuid
|
|
14
|
+
from ..context import ctx
|
|
15
|
+
from ..display import console
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def cmd_whoami(args: list[str]) -> None:
|
|
19
|
+
"""Show the active collector — and VALIDATE it against your account. SLAB_COLLECTOR is just a
|
|
20
|
+
string until it's checked, so this resolves it against the account behind your API key and
|
|
21
|
+
prints the collector's name. A wrong or stale UUID is caught HERE (with the list of collectors
|
|
22
|
+
you actually own) instead of surfacing later as a cryptic 'collector not found' mid-command."""
|
|
23
|
+
me = ctx.client.get_account_context()
|
|
24
|
+
names = {c.uuid: c.name for c in me.collectors}
|
|
25
|
+
uuid = get_collector_uuid()
|
|
26
|
+
|
|
27
|
+
if not uuid:
|
|
28
|
+
console.print("[yellow]SLAB_COLLECTOR is not set.[/yellow]")
|
|
29
|
+
_print_collectors(me, names)
|
|
30
|
+
return
|
|
31
|
+
|
|
32
|
+
name = names.get(uuid)
|
|
33
|
+
if name is None:
|
|
34
|
+
console.print(f"[red]SLAB_COLLECTOR is {uuid},[/red]")
|
|
35
|
+
console.print("[red]but that isn't a collector on this account.[/red]")
|
|
36
|
+
_print_collectors(me, names)
|
|
37
|
+
return
|
|
38
|
+
|
|
39
|
+
console.print(f"Active collector: [bold]{name}[/bold] [dim]{uuid}[/dim]")
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def _print_collectors(me: MeOut, names: dict[str, str]) -> None:
|
|
43
|
+
"""List the account's real collectors (marking the default) so the user knows what to set."""
|
|
44
|
+
if not names:
|
|
45
|
+
console.print("[dim]This account has no collectors yet.[/dim]")
|
|
46
|
+
return
|
|
47
|
+
console.print("[dim]Collectors on this account:[/dim]")
|
|
48
|
+
for c in me.collectors:
|
|
49
|
+
tag = " [dim](default)[/dim]" if c.uuid == me.default_collector_uuid else ""
|
|
50
|
+
console.print(f" [bold]{c.name}[/bold]{tag} [dim]{c.uuid}[/dim]")
|
|
51
|
+
console.print("[dim]Set one: export SLAB_COLLECTOR=<uuid>[/dim]")
|
|
@@ -5,11 +5,8 @@ calling _client()/_require_collector() themselves."""
|
|
|
5
5
|
|
|
6
6
|
from __future__ import annotations
|
|
7
7
|
|
|
8
|
-
import sys
|
|
9
|
-
|
|
10
8
|
from .client import SlabClient
|
|
11
9
|
from .config import get_api_key, get_base_url, get_collector_uuid
|
|
12
|
-
from .display import console
|
|
13
10
|
|
|
14
11
|
|
|
15
12
|
class MissingCollector(Exception):
|
|
@@ -31,21 +28,13 @@ class CliContext:
|
|
|
31
28
|
|
|
32
29
|
@property
|
|
33
30
|
def collector(self) -> str:
|
|
34
|
-
"""The active collector UUID
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
raises MissingCollector. Cached per invocation."""
|
|
31
|
+
"""The active collector UUID, from the SLAB_COLLECTOR env var. Required and explicit — the
|
|
32
|
+
CLI does not guess or auto-resolve a collector from the account. Copy your collector's UUID
|
|
33
|
+
from the portal (Settings) and set SLAB_COLLECTOR to it; if it's unset this raises
|
|
34
|
+
MissingCollector. Cached per invocation."""
|
|
39
35
|
if self._collector:
|
|
40
36
|
return self._collector
|
|
41
37
|
uuid = get_collector_uuid()
|
|
42
|
-
if not uuid:
|
|
43
|
-
# No explicit collector. Only a single-collector account may zero-config fall back to
|
|
44
|
-
# its default; a developer account has no unambiguous default and must set one.
|
|
45
|
-
me = self.client.get_account_context()
|
|
46
|
-
if me.account.account_type == "developer":
|
|
47
|
-
raise MissingCollector
|
|
48
|
-
uuid = me.default_collector_uuid
|
|
49
38
|
if not uuid:
|
|
50
39
|
raise MissingCollector
|
|
51
40
|
self._collector = uuid
|
|
@@ -8,6 +8,7 @@ one group; `slab <group> <command> --help` explains a single command.
|
|
|
8
8
|
|
|
9
9
|
from __future__ import annotations
|
|
10
10
|
|
|
11
|
+
import re
|
|
11
12
|
import sys
|
|
12
13
|
|
|
13
14
|
from .client import ApiConnectionError, ApiError
|
|
@@ -19,6 +20,16 @@ from .help import render_command_help, render_group_help, render_root_help
|
|
|
19
20
|
|
|
20
21
|
_HELP_FLAGS = ("-h", "--help", "help")
|
|
21
22
|
|
|
23
|
+
# assert_owned's 404 detail for an unknown/unowned collector is exactly "collector <uuid> not found".
|
|
24
|
+
# Distinct from copy/break/lot not-found details ("copy X not found for collector Y"), which name a
|
|
25
|
+
# parent collector but don't start with it — so anchoring to the start avoids false positives.
|
|
26
|
+
_MISSING_COLLECTOR_RE = re.compile(r"^collector \S+ not found$")
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def _is_missing_collector(detail: str | None) -> bool:
|
|
30
|
+
"""True when a 404 detail means the active collector itself is unknown to this account."""
|
|
31
|
+
return bool(detail and _MISSING_COLLECTOR_RE.match(detail))
|
|
32
|
+
|
|
22
33
|
|
|
23
34
|
def _run(args: list[str]) -> int:
|
|
24
35
|
"""Resolve `args` against the registry and run the command. Returns a process exit code."""
|
|
@@ -82,7 +93,14 @@ def main() -> None:
|
|
|
82
93
|
console.print("[dim] Check that the API is running and SLAB_API_URL is correct.[/dim]")
|
|
83
94
|
sys.exit(1)
|
|
84
95
|
except ApiError as e:
|
|
85
|
-
if e.status == 404:
|
|
96
|
+
if e.status == 404 and _is_missing_collector(e.detail):
|
|
97
|
+
# The active collector (SLAB_COLLECTOR) doesn't resolve to a live collector on this
|
|
98
|
+
# account. This otherwise surfaces mid-flow (e.g. picking Gift → fetching prior sources)
|
|
99
|
+
# as a cryptic "Not found" — point the user at the fix instead.
|
|
100
|
+
console.print("[red]Your active collector wasn't found for this account.[/red]")
|
|
101
|
+
console.print(" See which one the CLI is using: [bold]slab collector current[/bold]")
|
|
102
|
+
console.print(" Then set SLAB_COLLECTOR to a collector UUID from the portal (Settings).")
|
|
103
|
+
elif e.status == 404:
|
|
86
104
|
console.print(f"[yellow]Not found: {e.detail}[/yellow]")
|
|
87
105
|
elif e.status == 401:
|
|
88
106
|
console.print("[red]Unauthorized — check your SLAB_API_KEY.[/red]")
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
"""Setup commands — check identity.
|
|
2
|
-
|
|
3
|
-
Collectors are NOT created here. Your account and its collector are provisioned when you sign up
|
|
4
|
-
in the portal; the CLI just consumes the API key and collector UUID you get there. When
|
|
5
|
-
SLAB_COLLECTOR is unset the CLI falls back to your account's default collector (see context.py),
|
|
6
|
-
so a solo user only needs their API key.
|
|
7
|
-
"""
|
|
8
|
-
|
|
9
|
-
from __future__ import annotations
|
|
10
|
-
|
|
11
|
-
from ..config import get_collector_uuid
|
|
12
|
-
from ..display import console
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
def cmd_whoami(args: list[str]) -> None:
|
|
16
|
-
uuid = get_collector_uuid()
|
|
17
|
-
if uuid:
|
|
18
|
-
console.print(f"Active collector: [bold]{uuid}[/bold]")
|
|
19
|
-
else:
|
|
20
|
-
console.print(
|
|
21
|
-
"[dim]SLAB_COLLECTOR not set — the CLI will use your account's default collector.\n"
|
|
22
|
-
"Find your collector UUID and API key in the portal.[/dim]"
|
|
23
|
-
)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|