Skip to content

Commit

Permalink
Format profiles in a table
Browse files Browse the repository at this point in the history
  • Loading branch information
anticorrelator committed Jul 26, 2022
1 parent 79286c1 commit f67c4ab
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/prefect/cli/cloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ async def ls():

current_workspace = get_current_workspace(workspaces)

table = Table()
table = Table(caption="* active workspace")
table.add_column(
"[#024dfd]Available Workspaces:", justify="right", style="#8ea0ae", no_wrap=True
)
Expand Down
11 changes: 9 additions & 2 deletions src/prefect/cli/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import typer
from fastapi import status
from rich.progress import Progress, SpinnerColumn, TextColumn
from rich.table import Table

import prefect.context
import prefect.settings
Expand All @@ -33,11 +34,17 @@ def ls():
current_profile = prefect.context.get_settings_context().profile
current_name = current_profile.name if current_profile is not None else None

table = Table(caption="* active profile")
table.add_column(
"[#024dfd]Available Profiles:", justify="right", style="#8ea0ae", no_wrap=True
)

for name in profiles:
if name == current_name:
app.console.print(f"* {name}")
table.add_row(f"[green] * {name}[/green]")
else:
app.console.print(name)
table.add_row(f" {name}")
app.console.print(table)


@profile_app.command()
Expand Down
30 changes: 12 additions & 18 deletions tests/cli/test_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ def test_ls_default_profiles():
# 'default' is not the current profile because we have a temporary profile in-use
# during tests

invoke_and_assert(["profile", "ls"], expected_output="default")
invoke_and_assert(["profile", "ls"], expected_output_contains="default")


def test_ls_additional_profiles():
Expand All @@ -229,12 +229,10 @@ def test_ls_additional_profiles():

invoke_and_assert(
["profile", "ls"],
expected_output=(
"""
default
foo
bar
"""
expected_output_contains=(
"default",
"foo",
"bar",
),
)

Expand All @@ -251,11 +249,9 @@ def test_ls_respects_current_from_profile_flag():

invoke_and_assert(
["--profile", "foo", "profile", "ls"],
expected_output=(
"""
default
* foo
"""
expected_output_contains=(
"default",
"* foo",
),
)

Expand All @@ -274,12 +270,10 @@ def test_ls_respects_current_from_context():
with use_profile("bar"):
invoke_and_assert(
["profile", "ls"],
expected_output=(
"""
default
foo
* bar
"""
expected_output_contains=(
"default",
"foo",
"* bar",
),
)

Expand Down

0 comments on commit f67c4ab

Please sign in to comment.