fix(cloud): make session command help non-destructive

This commit is contained in:
bearsyankees 2026-08-27 17:35:56 -04:00
parent 1b9f41d244
commit 4765838330
2 changed files with 38 additions and 6 deletions

View file

@ -43,12 +43,7 @@ def run_cloud(argv: list[str]) -> int:
group, rest = argv[0], argv[1:]
if group in ("login", "logout", "whoami"):
session_argv = {
"login": rest,
"logout": ["logout"],
"whoami": ["status", *rest],
}
return run_login(session_argv[group])
return _run_session(console, group, rest)
if group == "credits":
group, rest = "billing", ["credits", *rest]
if group == "workspaces" and rest and rest[0] == "use":
@ -68,6 +63,20 @@ def run_cloud(argv: list[str]) -> int:
return run(group, verb_label, cmd, remaining)
def _run_session(console: Console, group: str, rest: list[str]) -> int:
if rest and rest[0] in ("-h", "--help", "help"):
return run_login(["--help"])
if group == "logout" and rest:
console.print("[red]Unknown argument for logout:[/] " + " ".join(rest))
return 2
session_argv = {
"login": rest,
"logout": ["logout"],
"whoami": ["status", *rest],
}
return run_login(session_argv[group])
def _print_usage(console: Console) -> None:
console.print(_USAGE_HEADER)
for group in SPEC:

View file

@ -634,3 +634,26 @@ def test_group_help_lists_all_verbs_instead_of_default_verb_help(capsys: Any) ->
assert "list" in output
assert "create" in output
assert "use" in output
def test_logout_help_does_not_remove_stored_auth(
monkeypatch: pytest.MonkeyPatch, tmp_path: Path, capsys: Any
) -> None:
auth_path = tmp_path / "platform-auth.json"
monkeypatch.setattr(platform_cli, "AUTH_PATH", auth_path)
platform_cli.save_record({"api_token": "keep-me"})
assert cloud.run_cloud(["logout", "--help"]) == 0
assert platform_cli.read_record() == {"api_token": "keep-me"}
assert "Usage:" in capsys.readouterr().out
def test_logout_rejects_unknown_arguments_without_removing_stored_auth(
monkeypatch: pytest.MonkeyPatch, tmp_path: Path
) -> None:
auth_path = tmp_path / "platform-auth.json"
monkeypatch.setattr(platform_cli, "AUTH_PATH", auth_path)
platform_cli.save_record({"api_token": "keep-me"})
assert cloud.run_cloud(["logout", "--bogus"]) == 2
assert platform_cli.read_record() == {"api_token": "keep-me"}