|
32 | 32 | TextColumn, |
33 | 33 | TimeElapsedColumn, |
34 | 34 | ) |
| 35 | +from rich.prompt import Prompt |
35 | 36 | from rich.table import Column, Table |
36 | 37 | from rich.text import Text |
37 | 38 | from rich_click.utils import CommandGroupDict, OptionGroupDict |
|
52 | 53 | convert_table_to_markdown, |
53 | 54 | ) |
54 | 55 | from bowtie._direct_connectable import Direct |
| 56 | +from bowtie._tui import TuiSession |
55 | 57 | from bowtie.exceptions import ( |
56 | 58 | CannotConnect, |
57 | 59 | DialectError, |
@@ -125,7 +127,7 @@ def _progress(*columns: Any) -> Progress: |
125 | 127 | "bowtie": [ |
126 | 128 | CommandGroupDict( |
127 | 129 | name="Basic Commands", |
128 | | - commands=["validate", "suite", "summary", "info"], |
| 130 | + commands=["tui", "validate", "suite", "summary", "info"], |
129 | 131 | ), |
130 | 132 | CommandGroupDict( |
131 | 133 | name="Advanced Usage", |
@@ -1378,6 +1380,47 @@ def run( |
1378 | 1380 | ) |
1379 | 1381 |
|
1380 | 1382 |
|
| 1383 | +@subcommand |
| 1384 | +@implementation_subcommand() |
| 1385 | +@dialect_option() |
| 1386 | +def tui(start: Any, dialect: Dialect, **kwargs: Any): |
| 1387 | + """ |
| 1388 | + Interactively evaluate schemas against instances across implementations. |
| 1389 | +
|
| 1390 | + Starts a REPL that keeps implementations running between validations, |
| 1391 | + prompting for a JSON Schema and an instance on each iteration |
| 1392 | + """ |
| 1393 | + |
| 1394 | + async def _tui(start: Any, dialect: Dialect, **kwargs: Any): |
| 1395 | + runners = [] |
| 1396 | + async for impl_id, implementation in start(): |
| 1397 | + try: |
| 1398 | + runner = await implementation.start_speaking(dialect) |
| 1399 | + except UnsupportedDialect as error: |
| 1400 | + STDERR.print(error) |
| 1401 | + continue |
| 1402 | + runners.append(( |
| 1403 | + impl_id, |
| 1404 | + implementation.info.version or "?", |
| 1405 | + runner, |
| 1406 | + )) |
| 1407 | + |
| 1408 | + if not runners: |
| 1409 | + STDERR.print( |
| 1410 | + "[bold red]No implementation started successfully![/]", |
| 1411 | + ) |
| 1412 | + return EX.CONFIG |
| 1413 | + session = TuiSession( |
| 1414 | + runners=runners, |
| 1415 | + dialect=dialect, |
| 1416 | + console=STDOUT, |
| 1417 | + prompt=lambda msg: Prompt.ask(msg), |
| 1418 | + ) |
| 1419 | + await session.repl() |
| 1420 | + |
| 1421 | + return asyncio.run(_tui(start=start, dialect=dialect, **kwargs)) |
| 1422 | + |
| 1423 | + |
1381 | 1424 | @subcommand |
1382 | 1425 | @dialect_option(default=None, callback=_set_dialect_via_schema) |
1383 | 1426 | @IMPLEMENTATION |
|
0 commit comments