Skip to content

Commit

Permalink
fix go back to acct
Browse files Browse the repository at this point in the history
  • Loading branch information
zzstoatzz committed Feb 26, 2025
1 parent 4d9c0d2 commit 139efa8
Show file tree
Hide file tree
Showing 2 changed files with 243 additions and 39 deletions.
25 changes: 21 additions & 4 deletions src/prefect/cli/cloud/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,6 @@ def prompt_select_from_list(
Returns:
str: the selected option
"""

current_idx = 0
selected_option = None

Expand Down Expand Up @@ -243,12 +242,16 @@ def build_table() -> Table:
exit_with_error("")
elif key == readchar.key.ENTER or key == readchar.key.CR:
selected_option = options[current_idx]
if isinstance(selected_option, tuple):
selected_option = selected_option[0]
# Break out of the loop immediately after setting selected_option
break

live.update(build_table(), refresh=True)

return selected_option
# Convert tuple to its first element if needed
if isinstance(selected_option, tuple):
selected_option = selected_option[0]

return selected_option


async def login_with_browser() -> str:
Expand Down Expand Up @@ -364,11 +367,13 @@ async def _prompt_for_account_and_workspace(
None,
"[bold]Go back to account selection[/bold]",
)

result = prompt_select_from_list(
app.console,
"Which workspace would you like to use?",
options=workspace_options + [go_back_option],
)

if not result:
return None, True
else:
Expand Down Expand Up @@ -688,10 +693,22 @@ async def set(
if not workspaces:
exit_with_error("No workspaces found in the selected account.")

# Store the original list of workspaces
original_workspaces = workspaces.copy()

go_back = True
workspace = None
loop_count = 0

while go_back:
loop_count += 1

# If we're going back, use the original list of workspaces
if loop_count > 1:
workspaces = original_workspaces.copy()

workspace, go_back = await _prompt_for_account_and_workspace(workspaces)

if workspace is None:
exit_with_error("No workspace selected.")

Expand Down
Loading

0 comments on commit 139efa8

Please sign in to comment.