From 73af4216675ac24283d08c8f80d5c3090d022860 Mon Sep 17 00:00:00 2001 From: Ross Smith II Date: Sun, 6 Jun 2021 10:37:14 -0700 Subject: [PATCH 1/3] feat: Add support for env vars in templates --- yadm | 3 +++ 1 file changed, 3 insertions(+) diff --git a/yadm b/yadm index 21d4d7c..24ef080 100755 --- a/yadm +++ b/yadm @@ -409,6 +409,9 @@ function replace_vars() { for (label in c) { gsub(("{{" blank "*yadm\\." label blank "*}}"), c[label]) } + for (label in ENVIRON) { + gsub(("{{" blank "*env\\." label blank "*}}"), ENVIRON[label]) + } } function conditions() { pattern = ifs blank "+(" From b0e08566588e4811b41086a68260050259aa72f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Paulo=20K=C3=B6ch?= Date: Mon, 24 Jan 2022 21:49:46 +0000 Subject: [PATCH 2/3] Add test --- test/test_unit_template_default.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/test/test_unit_template_default.py b/test/test_unit_template_default.py index ea2f904..faab58b 100644 --- a/test/test_unit_template_default.py +++ b/test/test_unit_template_default.py @@ -202,3 +202,22 @@ def test_include(runner, yadm, tmpdir): assert run.err == '' assert output_file.read() == EXPECTED_INCLUDE assert os.stat(output_file).st_mode == os.stat(input_file).st_mode + + +def test_env(runner, yadm, tmpdir): + """Test env""" + + input_file = tmpdir.join('input') + input_file.write('{{env.PWD}}', ensure=True) + input_file.chmod(FILE_MODE) + output_file = tmpdir.join('output') + + script = f""" + YADM_TEST=1 source {yadm} + set_awk + template_default "{input_file}" "{output_file}" + """ + run = runner(command=['bash'], inp=script) + assert run.success + assert run.err == '' + assert output_file.read() == os.environ['PWD'] From 487f030405852edb9d23ee3918aa9d9266830cc1 Mon Sep 17 00:00:00 2001 From: Ross Smith II Date: Tue, 25 Jan 2022 12:19:09 -0800 Subject: [PATCH 3/3] Update test/test_unit_template_default.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Paulo Köch --- test/test_unit_template_default.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_unit_template_default.py b/test/test_unit_template_default.py index faab58b..ab80025 100644 --- a/test/test_unit_template_default.py +++ b/test/test_unit_template_default.py @@ -220,4 +220,4 @@ def test_env(runner, yadm, tmpdir): run = runner(command=['bash'], inp=script) assert run.success assert run.err == '' - assert output_file.read() == os.environ['PWD'] + assert output_file.read().strip() == os.environ['PWD']