From bb666109a4c7d43991f5a59c05e9a9afe59a316b Mon Sep 17 00:00:00 2001 From: Valentin Lab Date: Tue, 26 Feb 2019 15:40:47 +0100 Subject: [PATCH] new: dev: added ``yaml_get_values`` helper function for charm. --- bin/compose-core | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/bin/compose-core b/bin/compose-core index 3790144..ae64200 100755 --- a/bin/compose-core +++ b/bin/compose-core @@ -311,6 +311,46 @@ EOF export -f merge_yaml_str +yaml_get_values() { + local sep=${1:-$'\n'} value input type first elt + input=$(cat -) + if [ -z "$input" ] || [ "$input" == "None" ]; then + return 0 + fi + type=$(e "$input" | shyaml get-type) + value= + case "$type" in + "sequence") + first=1 + while read-0 elt; do + elt="$(e "$elt" | yaml_get_interpret)" || return 1 + [ "$elt" ] || continue + if [ "$first" ]; then + first= + else + value+="$sep" + fi + first= + value+="$elt" + done < <(e "$input" | shyaml -y get-values-0) + ;; + "struct") + while read-0 val; do + value+=$'\n'"$(e "$val" | yaml_get_interpret)" || return 1 + done < <(e "$input" | shyaml -y values-0) + ;; + "NoneType") + value="" + ;; + "str"|*) + value+="$(e "$input" | yaml_get_interpret)" + ;; + esac + e "$value" +} +export -f yaml_get_values + + yaml_key_val_str() { local entries="$@"