From 9313ca14322dd8e3f2c1e6794ebe2ad09e20a9e2 Mon Sep 17 00:00:00 2001 From: Valentin Lab Date: Tue, 30 Jan 2024 22:17:44 +0100 Subject: [PATCH] new: [compose-core] ensure compatibility with new shyaml rust implementation --- bin/compose-core | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/bin/compose-core b/bin/compose-core index cb3d63d..f9a7c23 100755 --- a/bin/compose-core +++ b/bin/compose-core @@ -355,7 +355,7 @@ 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 + if [ -z "$input" ] || [[ "$input" =~ ^None|null$ ]]; then return 0 fi type=$(e "$input" | shyaml get-type) @@ -1122,7 +1122,7 @@ get_docker_compose_links() { [ "$type" == "run-once" ] && continue if [ "$tech_dep" == "reversed" ]; then deps+=("$(echo -en "$master_target_service:\n links:\n - $master_service")") - elif [ "$tech_dep" == "True" ]; then + elif [[ "$tech_dep" =~ ^(True|true)$ ]]; then deps+=("$(echo -en "$master_service:\n links:\n - $master_target_service")") fi ## XXXvlab: an attempt to add depends_on, but this doesn't work well actually @@ -1764,7 +1764,7 @@ cfg-get-value () { err "The key $WHITE$key$NORMAL was not found in relation's data." return 1 fi - echo "$out" | yaml_get_interpret + printf "%s\n" "$out" | yaml_get_interpret } export -f cfg-get-value @@ -1807,8 +1807,7 @@ export -f expand_vars yaml_get_interpret() { local content tag content=$(cat -) - tag=$(echo "$content" | shyaml -y get-value) || return 1 - tag="${tag%% *}" + tag=$(echo "$content" | shyaml get-type) || return 1 content=$(echo "$content" | shyaml get-value) || return 1 if ! [ "${tag:0:1}" == "!" ]; then echo "$content" || return 1 @@ -2403,7 +2402,7 @@ _get_metadata_provides() { return 0 fi - provides=$(printf "%s" "$metadata" | shyaml get-value -y -q provides "") + provides=$(printf "%s" "$metadata" | shyaml -q get-value -y provides "") [ "$provides" -a "$provides" != "''" ] || { touch "$cache_file"; return 0; } _get_provides_provides "$provides" | tee "$cache_file" @@ -3171,7 +3170,7 @@ _get_master_service_for_service_cached () { return 0 fi - if [ "$(echo "$metadata" | shyaml get-value "subordinate" 2>/dev/null)" != "True" ]; then + if ! [[ "$(echo "$metadata" | shyaml get-value "subordinate" 2>/dev/null)" =~ ^True|true$ ]]; then ## just return service name echo "$service" | tee "$cache_file" return 0 @@ -3295,7 +3294,7 @@ _get_docker_compose_mixin_from_metadata_cached() { mixins+=("$docker_compose") fi - if [ "$(echo "$metadata" | shyaml get-value "subordinate" 2>/dev/null)" == "True" ]; then + if [[ "$(echo "$metadata" | shyaml get-value "subordinate" 2>/dev/null)" =~ ^True|true$ ]]; then subordinate=true fi fi @@ -4067,7 +4066,7 @@ _graph_service() { metadata=$(charm.metadata "$charm") || return 1 subordinate=$(echo "$metadata" | shyaml get-value "subordinate" 2>/dev/null) - if [ "$subordinate" == "True" ]; then + if [[ "$subordinate" =~ ^True|true$ ]]; then requires="$(echo "$metadata" | shyaml get-value "requires" 2>/dev/null)" master_charm= while read-0 relation_name relation; do @@ -4109,8 +4108,8 @@ _graph_node_service() { cat <