Skip to content

Commit d68237e

Browse files
committed
Improve discoverability
1 parent 23119e9 commit d68237e

File tree

5 files changed

+61
-46
lines changed

5 files changed

+61
-46
lines changed

runbook/cli/commands/list.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
11
import click
2+
from runbook.cli.commands.show import get_notebook_header
3+
4+
5+
def get_notebook_title(notebook_path):
6+
header = get_notebook_header(notebook_path)
7+
if header:
8+
maybe_title = [line for line in header.split("\n") if line.startswith("# ")]
9+
if maybe_title:
10+
return maybe_title[0][2:].strip()
11+
return None
212

313

414
@click.command()
@@ -26,8 +36,10 @@ def list(ctx):
2636
# Print found runbooks in a nice format
2737
rprint("\n[bold blue]Templates:[/bold blue]")
2838
for runbook in sorted(templates):
29-
rprint(f"📔 {runbook}")
39+
title = get_notebook_title(runbook)
40+
rprint(f"📔 {title} - {runbook}")
3041

3142
rprint("\n[bold blue]Runs:[/bold blue]")
3243
for runbook in sorted(runs):
33-
rprint(f"📔 {runbook}")
44+
title = get_notebook_title(runbook)
45+
rprint(f"📔 {title} - {runbook}")

runbook/cli/commands/show.py

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,34 @@
11
import click
2+
import nbformat
23
from rich.console import Console
34
from rich.table import Table
45
from runbook.cli.commands.plan import get_notebook_language
56
from runbook.cli.validators import validate_runbook_file_path
7+
from runbook.constants import RUNBOOK_METADATA
68

79
import papermill as pm
810

911

12+
def get_notebook_header(notebook_path):
13+
"""Get the title (H1) and description (H2) from the notebook's markdown cells.
14+
15+
Args:
16+
notebook_path (str): Path to the notebook file
17+
18+
Returns:
19+
str: The header of the first markdown cell, or None if not found
20+
"""
21+
nb = nbformat.read(notebook_path, as_version=4)
22+
header = None
23+
24+
for cell in nb.cells:
25+
if cell.cell_type == "markdown":
26+
header = cell.source
27+
break
28+
29+
return header
30+
31+
1032
@click.command()
1133
@click.argument(
1234
"runbook", type=click.Path(file_okay=True), callback=validate_runbook_file_path
@@ -22,8 +44,13 @@ def show(ctx, runbook):
2244
console.print(f"\n[bold blue]Runbook:[/] {runbook}")
2345
console.print(f"[bold blue]Language:[/] {notebook_language}\n")
2446

47+
# Get and print title and description if available
48+
header = get_notebook_header(runbook)
49+
if header:
50+
console.print(f"[bold blue]Header:\n[/]{header}\n")
51+
2552
# Create and populate parameters table
26-
table = Table(show_header=True, header_style="bold magenta")
53+
table = Table(show_header=True, header_style="bold blue")
2754
table.add_column("Parameter")
2855
table.add_column("Default Value")
2956
table.add_column("Type")
@@ -33,6 +60,7 @@ def show(ctx, runbook):
3360
default = value["default"].rstrip(";")
3461
typing = value["inferred_type_name"] or ""
3562
help_text = value["help"] or ""
36-
table.add_row(param, default, typing, help_text)
63+
if param != RUNBOOK_METADATA:
64+
table.add_row(param, default, typing, help_text)
3765

3866
console.print(table)

runbooks/binder/_template-deno.ipynb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
"source": [
1414
"# TITLE\n",
1515
"\n",
16-
"## DESCRIPTION"
16+
"## DESCRIPTION\n",
17+
"\n",
18+
"Description continues in narrative form"
1719
]
1820
},
1921
{

tests/__snapshots__/cli_test.ts.snap

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -90,20 +90,14 @@ snapshot[`create 1`] = `
9090
}
9191
`;
9292

93-
snapshot[`init 1`] = `
94-
[
95-
"runbooks",
96-
]
97-
`;
98-
9993
snapshot[`list 1`] = `
10094
{
10195
exitCode: 0,
10296
stderr: "",
10397
stdout: "
10498
Templates:
105-
📔 runbooks/binder/_template-deno.ipynb
106-
📔 runbooks/binder/_template-python.ipynb
99+
📔 TITLE - runbooks/binder/_template-deno.ipynb
100+
📔 TITLE - runbooks/binder/_template-python.ipynb
107101
108102
Runs:
109103
",
@@ -118,14 +112,18 @@ snapshot[`show 1`] = `
118112
Runbook: runbooks/binder/_template-deno.ipynb
119113
Language: typescript
120114
121-
┏━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━┳━━━━━━━━━━━━━━━━┓
122-
ParameterDefault ValueTypeHelp
123-
┡━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━━━━╇━━━━━━━━━━━━━━━━┩
124-
server"main.xargs.io"string │ │
125-
arg1number │ │
126-
anArray │ ["a", "b"] │ string[] │ normally a / b
127-
__RUNBOOK_METADATA__ │ {} │ None │ │
128-
└──────────────────────┴─────────────────┴──────────┴────────────────┘
115+
Header:
116+
# TITLE
117+
118+
## DESCRIPTION
119+
120+
┏━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━┳━━━━━━━━━━━━━━━━┓
121+
ParameterDefault ValueTypeHelp
122+
┡━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━━━━╇━━━━━━━━━━━━━━━━┩
123+
server"main.xargs.io"string │ │
124+
arg1number │ │
125+
anArray │ ["a", "b"] │ string[] │ normally a / b
126+
└───────────┴─────────────────┴──────────┴────────────────┘
129127
',
130128
}
131129
`;

tests/cli_test.py

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -161,28 +161,3 @@ def test_cli_lifecycle_to_run():
161161
# TODO: fix multiple singletons of ServerApp
162162
# result = invoker(runner, ["run", deno_template], dir)
163163
# 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)