Skip to content

Commit

Permalink
Fix usage of '--replay-file' (Fixes #23) (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
ericof authored May 16, 2024
1 parent 93a94f1 commit 8cbbcc9
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 11 deletions.
29 changes: 18 additions & 11 deletions cookieplone/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from cookieplone.exceptions import GeneratorException
from cookieplone.generator import generate
from cookieplone.repository import get_base_repository, get_template_options
from cookieplone.utils import console, internal
from cookieplone.utils import console, files, internal


def validate_extra_context(value: list[str] | None = None) -> list[str]:
Expand Down Expand Up @@ -116,6 +116,8 @@ def cli(
if version:
console.base_print(internal.version_info())
raise typer.Exit()

configure_logger(stream_level="DEBUG" if verbose else "INFO", debug_file=debug_file)
repository = os.environ.get(settings.REPO_LOCATION)
if not repository:
repository = "gh:plone/cookieplone-templates"
Expand All @@ -127,19 +129,22 @@ def cli(
else:
console.welcome_screen()

if replay_file:
replay = replay_file
passwd = os.environ.get(
settings.REPO_PASSWORD, os.environ.get("COOKIECUTTER_REPO_PASSWORD")
)
if not output_dir:
output_dir = Path().cwd()
configure_logger(stream_level="DEBUG" if verbose else "INFO", debug_file=debug_file)
# Annotate extra_context
extra_context = parse_extra_content(extra_context)
extra_context["__generator_signature"] = internal.signature_md(repo_path)
extra_context["__cookieplone_repository_path"] = f"{repo_path}"
extra_context["__cookieplone_template"] = f"{template}"

replay_file = files.resolve_path(replay_file) if replay_file else replay_file
if replay_file and replay_file.exists():
# Use replay_file
replay = replay_file
else:
# Annotate extra_context
extra_context = parse_extra_content(extra_context)
extra_context["__generator_signature"] = internal.signature_md(repo_path)
extra_context["__cookieplone_repository_path"] = f"{repo_path}"
extra_context["__cookieplone_template"] = f"{template}"
# Run generator
try:
generate(
Expand All @@ -157,10 +162,12 @@ def cli(
skip_if_file_exists,
keep_project_on_failure,
)
except GeneratorException:
except GeneratorException as exc:
console.error(exc.message)
# TODO: Handle error
raise typer.Exit(1) # noQA:B904
except Exception:
except Exception as exc:
console.error(exc)
# TODO: Handle error
raise typer.Exit(1) # noQA:B904

Expand Down
7 changes: 7 additions & 0 deletions cookieplone/utils/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@
from cookiecutter.utils import rmtree


def resolve_path(path: Path | str) -> Path:
"""Resolve a path, including home user expansion."""
if f"{path}".startswith("~"):
path = path.expanduser()
return path.resolve()


def remove_files(base_path: Path, paths: list[str]):
"""Remove files."""
for filepath in paths:
Expand Down
1 change: 1 addition & 0 deletions news/23.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix usage of `--replay-file` [@ericof]

0 comments on commit 8cbbcc9

Please sign in to comment.