Browse Source

new: [compose-core] add ``upstream-version`` field in ``status`` action

fix-host-charm-resources
Valentin Lab 2 months ago
parent
commit
d46e9d8a84
  1. 46
      bin/compose-core

46
bin/compose-core

@ -2734,6 +2734,40 @@ service:state() {
}
export -f service:state
charm:upstream-version() {
local charm="$1" version cache_file="$state_tmpdir/$FUNCNAME.cache.$1" path
if [ -e "$cache_file" ]; then
cat "$cache_file"
return 0
fi
if ! path=$(charm.has_direct_action "$charm" "upstream-versions"); then
return 0
fi
version=$("$path" -l 1) || {
err "Failed to get upstream version for ${DARKYELLOW}$charm${NORMAL}."
return 1
}
if path=$(charm.has_direct_action "$charm" "upstream-version-normalize"); then
version=$("$path" "$version") || {
err "Failed to normalize upstream version for ${DARKYELLOW}$charm${NORMAL}."
return 1
}
fi
echo "$version" > "$cache_file"
e "$version"
}
export -f charm:upstream-version
service:upstream-version() {
local service="$1" version
charm=$(get_service_charm "$service") || return 1
version=$(charm:upstream-version "$charm") || return 1
e "$version"
}
export -f service:upstream-version
_get_charm_metadata_uses() {
local metadata="$1" cache_file="$CACHEDIR/$FUNCNAME.cache.$(printf "%s\0" "$@" | md5_compat)"
if [ -e "$cache_file" ]; then
@ -5650,7 +5684,7 @@ if [ "$action" == "status" ]; then
if [[ "$col" == "-"* ]]; then
col=${col#-}
fi
state_columns_raw+=("$col")
state_columns_raw+=("${col//-/_}")
done
state_columns_align=""
for col in "${state_columns[@]}"; do
@ -5667,7 +5701,7 @@ if [ "$action" == "status" ]; then
color=
value="${!col}"
read -r -- value_trim <<<"${!col}"
case "$col" in
case "${col//_/-}" in
root)
case "$value_trim" in
0) value=" ";;
@ -5721,12 +5755,12 @@ if [ "$action" == "status" ]; then
IFS="=" read -r key value <<<"$filter"
## if not already in state_columns_raw
[[ " ${state_columns_raw[*]} " == *" $key "* ]] ||
filter_cols+=("$key")
filter_cols+=("${key//-/_}")
done
for service in "${services_args[@]}"; do
declare -A values=()
for col in "${state_columns_raw[@]}" "${filter_cols[@]}"; do
case "$col" in
case "${col//_/-}" in
root)
if [[ " ${compose_yml_services[*]} " == *" ${service} "* ]]; then
value="1"
@ -5744,6 +5778,10 @@ if [ "$action" == "status" ]; then
type)
value=$(get_service_type "$service") || { echo 1; exit 1; }
;;
upstream-version)
value=$(service:upstream-version "$service") || { echo 1; exit 1; }
value=${value:-N/A}
;;
*)
if has_service_action "$service" "get-$col" >/dev/null; then
state_msg=$(run_service_action "$service" "get-$col") || { echo 1; exit 1 ; }

Loading…
Cancel
Save