From 1e811eae149d6282468354385e6cd3084582a5ff Mon Sep 17 00:00:00 2001 From: Dan Shernicoff Date: Sat, 6 Sep 2025 12:58:38 -0400 Subject: [PATCH 1/4] Fix issue #19 - double `CTRL-C` to exit with reload. --- src/render_engine_cli/event.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/render_engine_cli/event.py b/src/render_engine_cli/event.py index 6d1ec1c..531ba59 100644 --- a/src/render_engine_cli/event.py +++ b/src/render_engine_cli/event.py @@ -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""" From bbabdd8647347decdbf5bbbbc2dba21613410074 Mon Sep 17 00:00:00 2001 From: Dan Shernicoff Date: Sat, 6 Sep 2025 13:13:58 -0400 Subject: [PATCH 2/4] Fixes issue #17 - Allows input of content from STDIN on `new-entry` --- src/render_engine_cli/cli.py | 11 +++++++---- src/render_engine_cli/utils.py | 17 +++++++++++++++++ 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/render_engine_cli/cli.py b/src/render_engine_cli/cli.py index 2bb5c69..15a6c9b 100644 --- a/src/render_engine_cli/cli.py +++ b/src/render_engine_cli/cli.py @@ -18,6 +18,7 @@ get_editor, get_site, get_site_content_paths, + handle_content_file, remove_output_folder, split_args, split_module_site, @@ -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", @@ -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, @@ -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 diff --git a/src/render_engine_cli/utils.py b/src/render_engine_cli/utils.py index 2c3e79d..479e7b8 100644 --- a/src/render_engine_cli/utils.py +++ b/src/render_engine_cli/utils.py @@ -212,3 +212,20 @@ 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) + print(content) + 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() From d7cf1c824688c7c1a231aabbfb41c02adba0d35a Mon Sep 17 00:00:00 2001 From: Dan Shernicoff Date: Sat, 6 Sep 2025 13:34:47 -0400 Subject: [PATCH 3/4] Update utils.py Co-authored-by: John Aziz --- src/render_engine_cli/utils.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/render_engine_cli/utils.py b/src/render_engine_cli/utils.py index 479e7b8..f072c7f 100644 --- a/src/render_engine_cli/utils.py +++ b/src/render_engine_cli/utils.py @@ -221,7 +221,6 @@ def handle_content_file(ctx: click.Context, param: click.Option, value: str) -> click.secho('Please enter the content. To finish, put a "." on a blank line.', fg="green") while (line := input("")) != ".": content.append(line) - print(content) return "\n".join(content) path = Path(value) if not path.exists: From 0ea59993587fdc9a6a9ed73dd23cd8d08a45c36e Mon Sep 17 00:00:00 2001 From: Dan Shernicoff Date: Sat, 6 Sep 2025 13:34:58 -0400 Subject: [PATCH 4/4] Update utils.py Co-authored-by: John Aziz --- src/render_engine_cli/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/render_engine_cli/utils.py b/src/render_engine_cli/utils.py index f072c7f..fd66420 100644 --- a/src/render_engine_cli/utils.py +++ b/src/render_engine_cli/utils.py @@ -223,7 +223,7 @@ def handle_content_file(ctx: click.Context, param: click.Option, value: str) -> content.append(line) return "\n".join(content) path = Path(value) - if not path.exists: + if not path.exists(): raise click.exceptions.BadParameter( f'Either the path to a file or "stdin" must be provided. {repr(value)} is invalid.' )