in core/standalone.py [0:0]
def help_message(pipe):
from functools import partial
from rich import print
from rich.panel import Panel
from rich.table import Table
from rich.text import Text
from . import Pipe, _indirect
from .util import walk_contexts, walk_params
pipe_doc = pipe.func.__doc__
if not pipe_doc:
pipe_doc = "[i]This pipe has no description.[/i]"
config_entries = []
state_entries = []
for node, help, notes, type, default, empty in walk_params(pipe):
help = help or ""
if isinstance(node, Pipe.Config):
if notes is None:
notes = "" if default is empty else f"default: {repr(default)}"
config_entries.append([node.node, type.__name__, help, notes])
if isinstance(node, Pipe.State):
if node.node and node.node.startswith("runtime."):
continue
if node.node is not None:
if notes is None:
notes = "" if default is empty else f"default: {repr(default)}"
state_entries.append([node.node, type.__name__, help, notes])
elif node.indirect:
if notes is None:
notes = f"default: {repr(node.node)}"
config_entries.append([_indirect(node.indirect), type.__name__, help, notes])
notes = []
if pipe.notes:
notes += pipe.notes if isinstance(pipe.notes, list) else [str(pipe.notes)]
for ctx in walk_contexts(pipe):
ctx_notes = getattr(ctx, "notes", None) or []
notes += ctx_notes if isinstance(ctx_notes, list) else [str(ctx_notes)]
if pipe.closing_notes:
notes += pipe.closing_notes if isinstance(pipe.closing_notes, list) else [str(pipe.closing_notes)]
def _render_panel(title, entries):
table = Table(show_header=False, box=None, expand=False)
for entry in sorted(entries):
table.add_row(
Text(entry[0], style="bold cyan"),
Text(entry[1], style="bold yellow"),
entry[2],
Text(entry[3], style="dim"),
)
if not entries:
table.add_row("[i]none[/i]")
return Panel(table, title=title, title_align="left", border_style="dim")
def _render_notes(notes):
table = Table(show_header=False, box=None, expand=False)
for note in notes:
table.add_row(
Text("*", style="bold green"),
note,
)
return Panel(table, title="Notes", title_align="left", border_style="dim")
# print everything on standard error
print = partial(print, file=sys.stderr)
print(pipe_doc)
print()
print(_render_panel("Configuration parameters", config_entries))
print(_render_panel("State nodes", state_entries))
if notes:
print(_render_notes(notes))
print()
print("Use the [bold green]-p[/bold green] option to execute in UNIX pipe mode.")