Coverage for harbor_cli/output/table/_utils.py: 100%
16 statements
« prev ^ index » next coverage.py v6.5.0, created at 2023-02-09 12:09 +0100
« prev ^ index » next coverage.py v6.5.0, created at 2023-02-09 12:09 +0100
1from __future__ import annotations
3from typing import Any
4from typing import Sequence
6from rich.table import Table
8from ..formatting.builtin import plural_str
11def get_table(
12 title: str | None = None,
13 data: Sequence[Any] | None = None,
14 pluralize: bool = True,
15 columns: list[str] | None = None,
16 **kwargs: Any,
17) -> Table:
18 """Get a table with a title."""
19 # NOTE: This is a bug waiting to manifest itself.
20 # Maybe we should raise exception if we pass title and pluralize
21 # but not data.
22 if title and pluralize and data is not None:
23 title = plural_str(title, data)
25 # Set kwargs defaults (so we don't accidentally pass them twice)
26 kwargs.setdefault("show_header", True)
27 kwargs.setdefault("expand", True)
28 kwargs.setdefault("header_style", "bold magenta")
30 table = Table(
31 title=title,
32 **kwargs,
33 )
34 if columns is not None:
35 for column in columns:
36 table.add_column(column)
37 return table