Skip to content

Commit e8ece9a

Browse files
committed
👌 IMPROVE: Add --output to migrate command
1 parent 4297046 commit e8ece9a

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

sphinx_external_toc/cli.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,20 @@ def create_toc(site_dir, extension, index, skip_match, guess_titles, file_format
128128
type=click.Choice(["jb-v0.10"]),
129129
help="The format to migrate from.",
130130
)
131-
def migrate_toc(toc_file, format):
131+
@click.option(
132+
"-o",
133+
"--output",
134+
type=click.Path(allow_dash=True, exists=False, file_okay=True, dir_okay=False),
135+
help="Write to a file path.",
136+
)
137+
def migrate_toc(toc_file, format, output):
132138
"""Migrate a ToC from a previous revision."""
133139
toc = migrate_jupyter_book(Path(toc_file))
134-
click.echo(yaml.dump(toc, sort_keys=False, default_flow_style=False))
140+
content = yaml.dump(toc, sort_keys=False, default_flow_style=False)
141+
if output:
142+
path = Path(output)
143+
path.parent.mkdir(exist_ok=True, parents=True)
144+
path.write_text(content, encoding="utf8")
145+
click.secho(f"Written to: {path}", fg="green")
146+
else:
147+
click.echo(content)

0 commit comments

Comments
 (0)