Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions src/render_engine_cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
get_editor,
get_site,
get_site_content_paths,
handle_content_file,
remove_output_folder,
split_args,
split_module_site,
Expand Down Expand Up @@ -207,9 +208,11 @@ def serve(module_site: str, clean: bool, reload: bool, port: int):
)
@click.option(
"--content-file",
type=click.File("r"),
type=click.STRING,
callback=handle_content_file,
default=None,
help="Path to a file containing the desired content. Either this or `--content` may be provided but not both",
help="Path to a file containing the desired content. Using 'stdin' will ask you to enter the content in "
"the terminal. Either this or `--content` may be provided but not both",
)
@click.option(
"-t",
Expand Down Expand Up @@ -259,7 +262,7 @@ def new_entry(
module_site: str,
collection: str,
content: str,
content_file: click.File,
content_file: str,
title: str,
slug: str,
include_date: bool,
Expand Down Expand Up @@ -308,7 +311,7 @@ def new_entry(
if content and content_file:
raise TypeError("Both content and content_file provided. At most one may be provided.")
if content_file:
content = content_file.read()
content = content_file
entry = create_collection_entry(content=content or "", collection=_collection, **parsed_args)
if title:
# If we had a title earlier this is where we replace the default that is added by the template handler with
Expand Down
9 changes: 6 additions & 3 deletions src/render_engine_cli/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,12 @@ def watch(self) -> None:

console.print(f"[yellow]Serving {self.output_path}[/yellow]")
while not self.stop_watcher():
if self.dirs_to_watch:
for _ in watchfiles.watch(*self.dirs_to_watch):
self.rebuild()
try:
if self.dirs_to_watch:
for _ in watchfiles.watch(*self.dirs_to_watch):
self.rebuild()
except KeyboardInterrupt:
break

def __enter__(self):
"""Starting Context manager for the class"""
Expand Down
16 changes: 16 additions & 0 deletions src/render_engine_cli/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,3 +212,19 @@ def get_editor(ctx: click.Context, param: click.Option, value: str) -> str | Non
return None
case _:
return value


def handle_content_file(ctx: click.Context, param: click.Option, value: str) -> str | None:
"""Handle the content file"""
if value == "stdin":
content = list()
click.secho('Please enter the content. To finish, put a "." on a blank line.', fg="green")
while (line := input("")) != ".":
content.append(line)
return "\n".join(content)
path = Path(value)
if not path.exists():
raise click.exceptions.BadParameter(
f'Either the path to a file or "stdin" must be provided. {repr(value)} is invalid.'
)
return path.read_text()