Skip to content

Commit

Permalink
fix: Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
snaselj committed Oct 16, 2023
1 parent 8a74c2c commit ed4083f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,16 +100,18 @@ Output:
Usage: inv[oke] [--core-opts] bake [--options] [other tasks here ...]

Docstring:
Bake a cookiecutter template.
Bake a new cookie from the template.

Options:
-d, --debug Whether to run in debug mode (defaults to False)
-i, --[no-]input Whether to require user input (defaults to True)
-j STRING, --json-file=STRING Path to a JSON file containing answers to prompts
-o STRING, --output-dir=STRING Path to the output directory
-t STRING, --template=STRING Path to the cookiecutter template to bake
-i, --[no-]input Whether to require user input, ignored with `--json-file` (defaults to True)
-j STRING, --json-file=STRING Path to a JSON file containing answers to prompts (defaults to empty)
-o STRING, --output-dir=STRING Path to the output directory (defaults to ./outputs)
-t STRING, --template=STRING Path to the cookiecutter template to bake (defaults to ./nautobot-app)
```

!!! IMPORTANT !!! The `--output-dir` argument should be located in the current directory, as the Cookiecutter creates the cookie inside the Docker container with the current directory bind mounted. When baking somewhere else, the resulting cookie would not be available from calling host system.

### JSON file

You can reuse existing JSON file with pre-filled template prompts. To do so, you need to pass the path to the JSON file using the `--json-file` argument.
Expand Down
14 changes: 8 additions & 6 deletions tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -489,27 +489,29 @@ def help_task(context):
@task(
help={
"debug": "Whether to run in debug mode (defaults to False)",
"input": "Whether to require user input (defaults to True)",
"input": "Whether to require user input, ignored with `--json-file` (defaults to True)",
"json-file": "Path to a JSON file containing answers to prompts (defaults to empty)",
"output-dir": "Path to the output directory (defaults to ./outputs)",
"template": "Path to the cookiecutter template to bake (defaults to ./nautobot-app)",
},
)
def bake(context, debug=False, input=True, json_file="", output_dir="./outputs", template="./nautobot-app"):
"""Bake a cookiecutter template."""
def bake(context, _debug=False, _input=True, json_file="", output_dir="./outputs", template="./nautobot-app"):
"""Bake a new cookie from the template."""

Path(output_dir).mkdir(parents=True, exist_ok=True)

command = [
*_prefix_command(context),
"cookiecutter",
f"--output-dir={output_dir}",
"--no-input" if input is False else "",
f"--replay-file={json_file}" if json_file else "",
]

if debug:
command.append("--verbose");
if not _input:
command.append("--no-input")

if _debug:
command.append("--verbose")
command.append(f"--debug-file={output_dir}/debug.log")
command.append("--keep-project-on-failure")

Expand Down

0 comments on commit ed4083f

Please sign in to comment.