Skip to content

Commit 1756e4e

Browse files
yeldarbyclaude
andcommitted
fix(cli): workspace list falls back to API when no local config exists
When using ROBOFLOW_API_KEY or --api-key without having run `roboflow auth login`, `workspace list` now queries the API to resolve the workspace instead of showing empty results. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 4b600f0 commit 1756e4e

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

roboflow/cli/handlers/workspace.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,41 @@ def register(subparsers: argparse._SubParsersAction) -> None: # type: ignore[ty
2727

2828

2929
def _list_workspaces(args: argparse.Namespace) -> None:
30+
import os
31+
3032
from roboflow.cli._output import output
3133
from roboflow.cli._table import format_table
3234
from roboflow.config import APP_URL, get_conditional_configuration_variable
3335

3436
workspaces = get_conditional_configuration_variable("workspaces", default={})
3537
default_ws_url = get_conditional_configuration_variable("RF_WORKSPACE", default=None)
3638

39+
# When no workspaces in config, fall back to API using available API key
40+
if not workspaces:
41+
api_key = getattr(args, "api_key", None) or os.getenv("ROBOFLOW_API_KEY")
42+
if api_key:
43+
import requests
44+
45+
from roboflow.config import API_URL
46+
47+
resp = requests.post(API_URL + "/?api_key=" + api_key)
48+
if resp.status_code == 200:
49+
data = resp.json()
50+
ws_url = data.get("workspace", "")
51+
if ws_url:
52+
ws_name = ws_url
53+
try:
54+
from roboflow.adapters import rfapi
55+
56+
ws_json = rfapi.get_workspace(api_key, ws_url)
57+
ws_detail = ws_json.get("workspace", ws_json)
58+
ws_name = ws_detail.get("name", ws_url)
59+
except Exception: # noqa: BLE001
60+
pass
61+
workspaces = {ws_url: {"url": ws_url, "name": ws_name, "apiKey": api_key}}
62+
if not default_ws_url:
63+
default_ws_url = ws_url
64+
3765
rows = []
3866
for w in workspaces.values():
3967
rows.append(

0 commit comments

Comments
 (0)