Skip to content

Commit f37cb96

Browse files
committed
Add show command
1 parent d9b3af0 commit f37cb96

File tree

5 files changed

+68
-0
lines changed

5 files changed

+68
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ Commands:
6868
plan Prepares the runbook for execution by injecting parameters.
6969
review [Unimplemented] Entrypoint for reviewing runbook
7070
run Run a notebook
71+
show Show runbook parameters and metadata
7172
version Display version information about runbook
7273
```
7374

runbook/cli/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
plan,
1414
review,
1515
run,
16+
show,
1617
version,
1718
)
1819

@@ -45,6 +46,7 @@ def cli(ctx, cwd):
4546
cli.add_command(review)
4647
cli.add_command(version)
4748
cli.add_command(list)
49+
cli.add_command(show)
4850
# cli.add_command(export)
4951
cli.name = "runbook"
5052
cli

runbook/cli/commands/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@
88
from runbook.cli.commands.plan import plan
99
from runbook.cli.commands.review import review
1010
from runbook.cli.commands.run import run
11+
from runbook.cli.commands.show import show
1112
from runbook.cli.commands.version import version

runbook/cli/commands/show.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import click
2+
from rich.console import Console
3+
from rich.table import Table
4+
from runbook.cli.commands.plan import get_notebook_language
5+
from runbook.cli.validators import validate_runbook_file_path
6+
7+
import papermill as pm
8+
9+
10+
@click.command()
11+
@click.argument(
12+
"runbook", type=click.Path(file_okay=True), callback=validate_runbook_file_path
13+
)
14+
@click.pass_context
15+
def show(ctx, runbook):
16+
"""Show runbook parameters and metadata"""
17+
console = Console()
18+
inferred_params = pm.inspect_notebook(runbook)
19+
notebook_language = get_notebook_language(runbook)
20+
21+
# Print runbook info with styling
22+
console.print(f"\n[bold blue]Runbook:[/] {runbook}")
23+
console.print(f"[bold blue]Language:[/] {notebook_language}\n")
24+
25+
# Create and populate parameters table
26+
table = Table(show_header=True, header_style="bold magenta")
27+
table.add_column("Parameter")
28+
table.add_column("Default Value")
29+
table.add_column("Type")
30+
table.add_column("Help")
31+
32+
for param, value in inferred_params.items():
33+
default = value["default"].rstrip(";")
34+
typing = value["inferred_type_name"] or ""
35+
help_text = value["help"] or ""
36+
table.add_row(param, default, typing, help_text)
37+
38+
console.print(table)

tests/cli_test.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ def test_cli_help():
5656
plan Prepares the runbook for execution by injecting parameters.
5757
review [Unimplemented] Entrypoint for reviewing runbook
5858
run Run a notebook
59+
show Show runbook parameters and metadata
5960
version Display version information about runbook
6061
"""
6162
assert result.output == output
@@ -160,3 +161,28 @@ def test_cli_lifecycle_to_run():
160161
# TODO: fix multiple singletons of ServerApp
161162
# result = invoker(runner, ["run", deno_template], dir)
162163
# assert result.exit_code == 0
164+
165+
166+
def test_cli_lifecycle_to_show():
167+
runner = CliRunner()
168+
with runner.isolated_filesystem() as dir:
169+
result = invoker(runner, ["init"], dir)
170+
assert result.exit_code == 0
171+
result = invoker(runner, ["show", deno_template], dir)
172+
assert result.exit_code == 0
173+
assert (
174+
result.output
175+
== """
176+
Runbook: ./runbooks/binder/_template-deno.ipynb
177+
Language: typescript
178+
179+
┏━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━┳━━━━━━━━━━━━━━━━┓
180+
┃ Parameter ┃ Default Value ┃ Type ┃ Help ┃
181+
┡━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━━━━╇━━━━━━━━━━━━━━━━┩
182+
│ server │ "main.xargs.io" │ string │ │
183+
│ arg │ 1 │ number │ │
184+
│ anArray │ ["a", "b"] │ string[] │ normally a / b │
185+
│ __RUNBOOK_METADATA__ │ {} │ None │ │
186+
└──────────────────────┴─────────────────┴──────────┴────────────────┘
187+
"""
188+
)

0 commit comments

Comments
 (0)