Skip to content

Instantly share code, notes, and snippets.

@diversario
Last active July 16, 2018 04:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save diversario/407ec14d30d6936bf9e259f6e9f15933 to your computer and use it in GitHub Desktop.
Save diversario/407ec14d30d6936bf9e259f6e9f15933 to your computer and use it in GitHub Desktop.
Format YAML map as docker cli env vars
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