Created
January 8, 2022 02:30
-
-
Save jclosure/8e1c34f0588bd77367790f6ea488d6fe to your computer and use it in GitHub Desktop.
modify yaml on the fly as part of a make task
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
UNAME := $(shell uname) | |
### | |
# | |
# assuming a yaml like this: | |
# main: | |
# device: 21 | |
# | |
### | |
# semantic parsing and changing of the yaml | |
set-device-mode: | |
ifeq ($(UNAME), Linux) | |
if ! command -v yq &> /dev/null ; then \ | |
wget -qO /usr/local/bin/yq https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64; \ | |
chmod a+x /usr/local/bin/yq; \ | |
fi | |
endif | |
yq e -i '.main.device = 22' ./params.yaml | |
run: set-device-mode | |
echo "starting program" |
Test replacement regex matches easily in shell:
sed -E 's/(\s+device:\s)(21)/\122/g' ./spiff_params/params.yaml | diff params.yaml -
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Use the following
pre-commit
hook to revert it before checking back into VCS: