diff --git a/cookieplone/cli.py b/cookieplone/cli.py index 96ac439..a32e925 100644 --- a/cookieplone/cli.py +++ b/cookieplone/cli.py @@ -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]: @@ -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" @@ -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( @@ -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 diff --git a/cookieplone/utils/files.py b/cookieplone/utils/files.py index e14ce23..ee30cbe 100644 --- a/cookieplone/utils/files.py +++ b/cookieplone/utils/files.py @@ -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: diff --git a/news/23.bugfix b/news/23.bugfix new file mode 100644 index 0000000..849cb12 --- /dev/null +++ b/news/23.bugfix @@ -0,0 +1 @@ +Fix usage of `--replay-file` [@ericof]