Skip to content

Commit fd4bfcc

Browse files
committed
feat: show flow schema in cli command
1 parent 9e34793 commit fd4bfcc

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

python/cocoindex/cli.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,26 @@ def ls(show_all: bool):
5454
@cli.command()
5555
@click.argument("flow_name", type=str, required=False)
5656
@click.option("--color/--no-color", default=True)
57-
def show(flow_name: str | None, color: bool):
57+
@click.option(
58+
"--schema", is_flag=True, show_default=True, default=False,
59+
help="Also show the schema of the flow.")
60+
def show(flow_name: str | None, color: bool, schema: bool):
5861
"""
5962
Show the flow spec in a readable format with colored output.
63+
Optionally display the schema if --schema is provided.
6064
"""
61-
fl = _flow_by_name(flow_name)
65+
from rich.table import Table
66+
flow = _flow_by_name(flow_name)
6267
console = Console(no_color=not color)
63-
console.print(fl._render_text())
68+
console.print(flow._render_text())
69+
if schema:
70+
table = Table(title=f"Schema for Flow: {flow.name}", show_header=True, header_style="bold magenta")
71+
table.add_column("Field", style="cyan")
72+
table.add_column("Type", style="green")
73+
table.add_column("Attributes", style="yellow")
74+
for field_name, field_type, attr_str in flow._render_schema():
75+
table.add_row(field_name, field_type, attr_str)
76+
console.print(table)
6477

6578
@cli.command()
6679
def setup():

python/cocoindex/flow.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,12 @@ def _render_text(self) -> Text:
503503
return self._format_flow(flow_dict)
504504
except json.JSONDecodeError:
505505
return Text(flow_spec_str)
506+
507+
def _render_schema(self) -> list[tuple[str, str, str]]:
508+
"""
509+
Render the schema as a list of (field_name, field_type, attributes) tuples.
510+
"""
511+
return _engine.get_flow_schema(self.name)
506512

507513
def __str__(self):
508514
return str(self._render_text())

0 commit comments

Comments
 (0)