Skip to content

Commit

Permalink
Expand display_table column type annotation
Browse files Browse the repository at this point in the history
  • Loading branch information
mwaskom committed May 9, 2024
1 parent 4dab910 commit 5e62416
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions modal/cli/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import typer
from rich.console import Console
from rich.json import JSON
from rich.table import Table
from rich.table import Column, Table
from rich.text import Text


Expand All @@ -26,14 +26,17 @@ def _plain(text: Union[Text, str]) -> str:


def display_table(
column_names: List[str], rows: Sequence[Sequence[Union[Text, str]]], json: bool = False, title: str = None
columns: List[Union[str, Column]],
rows: Sequence[Sequence[Union[Text, str]]],
json: bool = False,
title: str = None,
):
console = Console()
if json:
json_data = [{col: _plain(row[i]) for i, col in enumerate(column_names)} for row in rows]
json_data = [{col: _plain(row[i]) for i, col in enumerate(columns)} for row in rows]
console.print(JSON.from_data(json_data))
else:
table = Table(*column_names, title=title)
table = Table(*columns, title=title)
for row in rows:
table.add_row(*row)
console.print(table)
Expand Down

0 comments on commit 5e62416

Please sign in to comment.