From c83a4f115a96b81cb70d5ea8b3e64ccdcb435a02 Mon Sep 17 00:00:00 2001 From: Slawek Koszewski Date: Wed, 17 Dec 2025 07:59:19 +0100 Subject: [PATCH] Fix: adopted volume list parsing for docker CLI. --- azure-cli | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/azure-cli b/azure-cli index 68c18b9..e697f14 100755 --- a/azure-cli +++ b/azure-cli @@ -80,13 +80,25 @@ fi if [ -n "$LIST" ]; then echo "Available accounts:" - $CMD volume ls --format json | jq -r '.[] | select(.labels | has("account")) | .labels.account' + # Unfortunately 'container' and 'docker' CLIs are not compatible + if [ "container" = "$CMD" ]; then + $CMD volume ls --format json | jq -r '.[] | select(.labels | has("account")) | .labels.account' + else + # Docker has settled to provide labels as one string, that's inconvinient + $CMD volume ls --format=json | jq -sr '.[] | .Account = (.Labels | match("account=([a-zA-Z0-9._%@+-]+)"; "x") | .captures[0].string) | .Account' + fi exit 0 fi +if [ "container" = "$CMD" ]; then + _FOUND="$($CMD volume ls --format json | jq -r --arg name "$VOLUME_NAME" --arg account "$ACCOUNT_NAME" '.[] | select(.name == $name or .labels.account == $account) | "FOUND"')" +else + _FOUND="$($CMD volume ls --format=json | jq -sr --arg name "$VOLUME_NAME" --arg account "$ACCOUNT_NAME" '.[] | .Account = (.Labels | match("account=([a-zA-Z0-9._%@+-]+)"; "x") // {} | .captures[0].string) | select(.Name == $name or .Account == $account) | "FOUND"')" +fi + # Check, if the account volume exists, if not create it # This ensures persistent storage for the Azure CLI configuration -if [ ! "FOUND" = "$($CMD volume ls --format json | jq -r --arg name "$VOLUME_NAME" --arg account "$ACCOUNT_NAME" '.[] | select(.name == $name or .labels.account == $account) | "FOUND"')" ]; then +if [ ! "FOUND" = "$_FOUND" ]; then echo "A volume for account '$ACCOUNT_NAME' does not exist." read -p "Would you like to create one? (y/n) " -r RESPONSE if [[ ! "$RESPONSE" =~ ^[Yy]$ ]]; then