Skip to content

Commit

Permalink
Merge pull request #166 from Tecnativa/fix-custom-answers-file-cli
Browse files Browse the repository at this point in the history
Fix --answers-file
  • Loading branch information
yajo authored Mar 25, 2020
2 parents de5a1ec + 58210e6 commit 7049a62
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion copier/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class CopierApp(cli.Application):
CALL_MAIN_IF_NESTED_COMMAND = False
data: AnyByStrDict = {}

answers_file = cli.Flag(
answers_file = cli.SwitchAttr(
["-a", "--answers-file"],
default=None,
help=(
Expand Down
2 changes: 2 additions & 0 deletions tests/demo_simple/[[ _copier_conf.answers_file ]].tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Changes here will be overwritten by Copier
[[ _copier_answers|to_nice_yaml ]]
8 changes: 7 additions & 1 deletion tests/test_cli.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from pathlib import Path

import yaml
from plumbum.cmd import copier as copier_cmd

from copier.cli import CopierApp
Expand All @@ -8,12 +9,17 @@


def test_good_cli_run(dst):
run_result = CopierApp.run(["--quiet", str(SIMPLE_DEMO_PATH), str(dst)], exit=False)
run_result = CopierApp.run(
["--quiet", "-a", "altered-answers.yml", str(SIMPLE_DEMO_PATH), str(dst)],
exit=False,
)
a_txt = dst / "a.txt"
assert run_result[1] == 0
assert a_txt.exists()
assert a_txt.is_file()
assert a_txt.read_text().strip() == "EXAMPLE_CONTENT"
answers = yaml.safe_load((dst / "altered-answers.yml").read_text())
assert answers["_src_path"] == str(SIMPLE_DEMO_PATH)


def test_help():
Expand Down

0 comments on commit 7049a62

Please sign in to comment.