Browse Source

new: [compose-core] add ``--get-available-actions`` commands

master
Valentin Lab 7 months ago
parent
commit
15ac855df8
  1. 59
      bin/compose-core

59
bin/compose-core

@ -2065,6 +2065,34 @@ get_compose_relations () {
export -f get_compose_relations
get_all_services() {
local cache_file="$state_tmpdir/$FUNCNAME.cache.$(H "$ALL_RELATIONS")" \
s rn ts rc td services
if [ -e "$cache_file" ]; then
#debug "$FUNCNAME: SESSION cache hit $1"
cat "$cache_file"
return 0
fi
if [ -z "$ALL_RELATIONS" ]; then
err "Can't access global \$ALL_RELATIONS"
return 1
fi
declare -A services
while read-0 s _ ts _ _; do
for service in "$s" "$ts"; do
[ "${services[$service]}" ] && continue
services["$service"]=1
echo "$service"
done
done < <(cat "$ALL_RELATIONS") > "$cache_file"
cat "$cache_file"
}
export -f get_all_services
get_service_relations () {
local service="$1" cache_file="$state_tmpdir/$FUNCNAME.cache.$(H "$@" "$ALL_RELATIONS")" \
s rn ts rc td
@ -3803,6 +3831,31 @@ display_commands_help() {
fi
}
get_docker_charm_action() {
local services service charm relation_name target_service relation_config \
target_charm
services=($(get_compose_yml_content | yq -r 'keys().[]' 2>/dev/null)) || return 1
NO_CONSTRAINT_CHECK=1 get_all_relations "${services[@]}" >/dev/null || return 1
services=($(get_all_services)) || return 1
for service in "${services[@]}"; do
printf "%s:\n" "$service"
charm=$(get_service_charm "$service") || return 1
for action in $(charm.ls_direct_actions "$charm"); do
printf " %s:\n" "$action"
printf " type: %s\n" "direct"
done
while read-0 relation_name target_service _relation_config _tech_dep; do
target_charm=$(get_service_charm "$target_service") || return 1
for action in $(charm.ls_relation_actions "$target_charm" "$relation_name"); do
printf " %s:\n" "$action"
printf " type: %s\n" "indirect"
printf " inherited: %s\n" "$target_charm"
done
done < <(get_service_relations "$service")
done
}
export -f get_docker_charm_action
get_docker_charm_action_help() {
local services service charm relation_name target_service relation_config \
target_charm
@ -3841,6 +3894,8 @@ display_help() {
echo " (ignoring any other options)"
echo " --get-project-name Display project name and quit"
echo " (ignoring any other options)"
echo " --get-available-actions Display all available actions and quit"
echo " (ignoring any other options)"
echo " -v, --verbose Be more verbose"
echo " -q, --quiet Be quiet"
echo " -d, --debug Print full debugging information (sets also verbose)"
@ -4198,6 +4253,10 @@ while read-0 arg; do
echo "$project"
exit 0
;;
--get-available-actions)
get_docker_charm_action
exit $?
;;
--dry-compose-run)
export DRY_COMPOSE_RUN=true
;;

Loading…
Cancel
Save