# shellcheck shell=dash

___x_cmd_webtop_image_pull(){
    local update=""
    case "$1" in
        -h|--help)      ___x_cmd help -m webtop image pull; return  ;;
        --update)       update=1                                    ;;
    esac

    local image="$1"
    image="${image#*/webtop:}";   [ -n "$image" ] || M='Provide a webtop image' N=webtop log:ret:1
    image="${___X_CMD_WEBTOP_URL_PREFIX}/webtop:$image"

    if [ "$image" = "${___X_CMD_WEBTOP_URL_PREFIX}/webtop:alpine-xfce" ]; then
        image="${___X_CMD_WEBTOP_URL_PREFIX}/webtop:latest"
    fi

    if [ -z "$update" ]; then
        ___x_cmd docker mirror pull --noupdate  "$image" || return $?
    else
        ___x_cmd docker mirror pull             "$image" || return $?
    fi

    if [ "$image" = "${___X_CMD_WEBTOP_URL_PREFIX}/webtop:latest" ]; then
        ___x_cmd docker tag "$image" "${___X_CMD_WEBTOP_URL_PREFIX}/webtop:alpine-xfce"
        ___x_cmd docker rmi "${___X_CMD_WEBTOP_URL_PREFIX}/webtop:latest"
    fi
}

