Last active
July 16, 2018 04:37
-
-
Save diversario/407ec14d30d6936bf9e259f6e9f15933 to your computer and use it in GitHub Desktop.
Format YAML map as docker cli env vars
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
yq -Mrj ' .envVars as $e | $e | keys | .[] | "-e \(.)=\($e[.]) "' deployment/values.yaml | |
function envvars() { | |
local selector=$1; shift | |
local files=($@) | |
if [[ -z $files ]]; then | |
files="${selector}" | |
selector=".envVars" | |
fi | |
local merge_string='.[0]' | |
local num_elements=$((${#files[@]}-1)) | |
if [[ $num_elements -gt 0 ]]; then | |
for i in $(seq $num_elements); do | |
merge_string="$merge_string * .[$i]" | |
done | |
fi | |
yq -s "$merge_string" $files | yq -Mrj $selector' as $e | $e | keys | .[] | "-e \(.)=\($e[.]) "' | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment