Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed output #218

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 22 additions & 5 deletions dem/cli/command/list_tools_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
from dem.core.platform import Platform
from dem.core.tool_images import ToolImage
from dem.cli.console import stdout, stderr
# from rich.__main__ import make_test_card
from rich.table import Table
import typer


def list_local_tools(platform: Platform) -> None:
""" List the local tools.

Expand All @@ -23,7 +25,7 @@ def list_local_tools(platform: Platform) -> None:
stdout.print("[yellow]No local tool images are available.[/]")
raise typer.Abort()

stdout.print(f"\n [italic]Local Tool Images[/]")
stdout.print(f"\n [#8f64eb][italic]Local Tool Images[/]")
# sorted will return a list of tuples, so we can iterate over the items
for tool_image in sorted(platform.tool_images.all_tool_images.items()):
# tool_image[0] is the name of the tool image and tool_image[1] is the ToolImage instance
Expand Down Expand Up @@ -93,8 +95,11 @@ def list_tools_from_selected_regs(platform: Platform, specified_regs: list[str])

table = Table()
list_tools_from_regs(platform, table)
table.add_row()
stdout.print(f"\n [italic]Available Tool Images from the selected registries[/]")
stdout.print(table)
# print content of table using pager
with stdout.pager(styles=True):
stdout.print(table)

def list_tools_from_all_regs(platform: Platform) -> None:
""" List the available tools from all registries.
Expand All @@ -111,8 +116,9 @@ def list_tools_from_all_regs(platform: Platform) -> None:

table = Table()
list_tools_from_regs(platform, table)
stdout.print(f"\n [italic]Available Tool Images from all registries[/]")
stdout.print(table)
with stdout.pager(styles=True):
stdout.print(f"\n [#8f64eb][italic]Available Tool Images from all registries[/]")
stdout.print(table)

def execute(platform: Platform, reg: bool, selected_regs: list[str]) -> None:
""" List the available tools.
Expand All @@ -126,9 +132,20 @@ def execute(platform: Platform, reg: bool, selected_regs: list[str]) -> None:
typer.Abort -- if no tool images are available either locally or in the registries or
if an unknown registry is specified
"""
# from rich.console import Console
# console = Console()
# with console.pager():
# console.print(make_test_card())
if not reg:
# with console.pager():
# # console.print(make_test_card())
# list_local_tools(platform))
list_local_tools(platform)
elif selected_regs:
# with console.pager():
# console.print(list_tools_from_selected_regs(platform, selected_regs))
list_tools_from_selected_regs(platform, selected_regs)
else:
list_tools_from_all_regs(platform)
# with console.pager():
# console.print(list_tools_from_all_regs(platform))
list_tools_from_selected_regs(platform, selected_regs)
3 changes: 2 additions & 1 deletion dem/cli/console.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
from rich.console import Console

stdout = Console(highlight=False)
stderr = Console(stderr=True)
stderr = Console(stderr=True)
console = Console()
4 changes: 2 additions & 2 deletions tests/cli/test_list_tools_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def test_list_local_tools(mock_print: MagicMock) -> None:
list_tools_cmd.list_local_tools(mock_platform)

# Check the result
mock_print.assert_has_calls([call("\n [italic]Local Tool Images[/]"),
mock_print.assert_has_calls([call("\n [#8f64eb][italic]Local Tool Images[/]"),
call(" test_tool_image")])

@patch("dem.cli.command.list_tools_cmd.stderr.print")
Expand Down Expand Up @@ -171,7 +171,7 @@ def test_list_tools_from_all_regs(mock_Table: MagicMock, mock_list_tools_from_re
mock_platform.tool_images.get_registry_ones.assert_called_once()
mock_Table.assert_called_once()
mock_list_tools_from_regs.assert_called_once_with(mock_platform, mock_table)
mock_print.assert_has_calls([call("\n [italic]Available Tool Images from all registries[/]"),
mock_print.assert_has_calls([call("\n [#8f64eb][italic]Available Tool Images from all registries[/]"),
call(mock_table)])

@patch("dem.cli.command.list_tools_cmd.stdout.print")
Expand Down