Conditionals inside recipe body based on arguments and preview when confirm attribute is set
I couldn't find duplicate issues until 6 pages deep..
I work in airflow repos and the folder structure is as follows:
dags
... templates
... utils
... other_files.py
plugins
... utils
... other_files.py
I wanted to make a simple just recipe for scp-ing each of those folders to a particular ssh target, given their names as arguments.
I wish the following syntax works:
# justfile
scp folder target:
If $folder == "plugins" {
scp -r ./plugins {{ target }}:./dev
}
else {
scp -r ./dags/{{ folder }} {{ target }}:./dev/dags
}
Doing the same in bash like such gives a lengthy incomprehensible output:
if [ "{{ folder }}" == "plugins" ]; then \
scp -r ./plugins {{ target }}:./dev \
else \
scp -r ./dags/{{ folder }} {{ target }}:./dev/dags; \
fi
Output of just scp utils server
if [ "utils" == "plugins" ]; then scp -r ./plugins server:./dev else scp -r ./dags/utils server:./dev/dags; fi
Also, I wish the preview is given when the confirm attribute is set instead of just Run recipe 'scp'? similar to --evaluate
Pun unintentional.. 😂
I wish the following syntax works:
Can you put the entire conditional in an interpolation? -
# justfile
scp folder target:
{{if folder == "plugins" { \
"scp -r ./plugins " + target + ":./dev" \
} \
else { \
"scp -r ./dags/" + folder + " " + target + ":./dev/dags" \
} }}
Can you put the entire conditional in an interpolation? -
Okay.. I'd say that solves the first half of the issue! ♥️
Have to check the output.. Will update
To make the bash version nicer, you can also do:
scp folder target:
!#/usr/bin/env bash
set -euxo pipefail
if [ "{{ folder }}" == "plugins" ]; then
scp -r ./plugins {{ target }}:./dev
else
scp -r ./dags/{{ folder }} {{ target }}:./dev/dags
fi