Skip to content

Commit bc18fe0

Browse files
committed
(bug) Fix duplicate file extension printed during create
1 parent aa9f82b commit bc18fe0

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

runbook/cli/commands/create.py

+11-3
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,19 @@
33
import click
44

55
from runbook.cli.lib import nbconvert_launch_instance
6-
from runbook.cli.validators import validate_create_language, validate_template
6+
from runbook.cli.validators import (
7+
validate_create_language,
8+
validate_has_notebook_extension,
9+
validate_template,
10+
)
711

812

913
@click.command()
10-
@click.argument("filename", type=click.Path(exists=False, file_okay=True))
14+
@click.argument(
15+
"filename",
16+
type=click.Path(exists=False, file_okay=True),
17+
callback=validate_has_notebook_extension,
18+
)
1119
@click.option(
1220
"-t",
1321
"--template",
@@ -76,6 +84,6 @@ def create(ctx, filename, template, language):
7684

7785
click.echo(
7886
click.style(
79-
f"$> runbook edit ./runbooks/binder/{filename}.ipynb", fg="green", bold=True
87+
f"$> runbook edit ./runbooks/binder/{filename}", fg="green", bold=True
8088
)
8189
)

runbook/cli/validators.py

+7-4
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,14 @@ def process_glob_matches(options):
7878
raise click.BadOptionUsage("FILENAME", f"unable to find {value} file")
7979

8080

81-
def validate_planned_runbook_file_path(ctx, param, value):
82-
ext = path.splitext(value)[-1].lower()
83-
if not ext == ".ipynb":
84-
ext = ".ipynb"
81+
def validate_has_notebook_extension(ctx, param, value):
82+
if not value.lower().endswith(".ipynb"):
8583
value = value + ".ipynb"
84+
return value
85+
86+
87+
def validate_planned_runbook_file_path(ctx, param, value):
88+
value = validate_has_notebook_extension(ctx, param, value)
8689
base_name = path.basename(value)
8790
try:
8891
if Path(value).exists():

0 commit comments

Comments
 (0)