Skip to content

Commit 19d50ce

Browse files
committed
format stagpy config output with rich
1 parent 2dd2c72 commit 19d50ce

File tree

2 files changed

+18
-17
lines changed

2 files changed

+18
-17
lines changed

src/stagpy/commands.py

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@
99
from shutil import get_terminal_size
1010
from textwrap import TextWrapper, indent
1111

12+
from rich import box
1213
from rich.columns import Columns
1314
from rich.console import Console
15+
from rich.table import Table
1416

1517
from . import __version__, phyvars
1618
from ._helpers import baredoc, walk
@@ -161,22 +163,28 @@ def config_pp(subs: Iterable[str], conf: Config) -> None:
161163
subs: conf sections to print.
162164
conf: configuration.
163165
"""
164-
print("(c|f): available only as CLI argument/in the config file", end="\n\n")
166+
console = Console()
165167
for sub in subs:
168+
table = Table(title=sub, box=box.SIMPLE)
169+
table.add_column(header="option", no_wrap=True)
170+
table.add_column(header="doc")
171+
table.add_column(header="cli", no_wrap=True)
172+
table.add_column(header="file", no_wrap=True)
173+
166174
section: Section = getattr(conf, sub)
167-
hlp_lst = []
168175
for fld in fields(section):
169176
opt = fld.name
170177
entry = section.meta_(opt).entry
171-
if entry.in_cli ^ entry.in_file:
172-
opt += " (c)" if entry.in_cli else " (f)"
173-
hlp_lst.append((opt, entry.doc))
174-
if hlp_lst:
175-
print(f"{sub}:")
176-
_pretty_print(
177-
hlp_lst, sep=" -- ", text_width=min(get_terminal_size().columns, 100)
178+
table.add_row(
179+
opt,
180+
entry.doc,
181+
"yes" if entry.in_cli else "no",
182+
"yes" if entry.in_file else "no",
178183
)
179-
print()
184+
185+
if table.rows:
186+
console.print(table)
187+
console.print()
180188

181189

182190
def config_cmd(conf: Config) -> None:

tests/test_commands.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,3 @@ def test_version_cmd(capsys: CaptureFixture) -> None:
2323
output = capsys.readouterr()
2424
expected = "stagpy version: {}\n".format(__version__)
2525
assert output.out == expected
26-
27-
28-
def test_config_cmd(capsys: CaptureFixture) -> None:
29-
commands.config_cmd(Config.default_())
30-
output = capsys.readouterr()
31-
expected = "(c|f): available only as CLI argument/in the config file"
32-
assert output.out.startswith(expected)

0 commit comments

Comments
 (0)