# shellcheck shell=dash

___x_cmd_webtop_container_rm(){
    local x_=""
    while [ $# -gt 0 ]; do
        case "$1" in
            -h|--help)  ___x_cmd help -m webtop rm         ; return ;;
            -a|--all)   ___x_cmd_webtop_container_rm___all ; return ;;
            --id)       x_="$2";    shift 2 ;;
            *)          break ;;
        esac
    done

    [ -n "$x_" ] || ___x_cmd_webtop_container_id_ "$1" || N=webtop M="Not found any container" log:ret:1

    ___x_cmd docker -- rm "$x_"
    ! ___x_cmd_runmode_allow_chatty || ___x_cmd webtop ps
}

___x_cmd_webtop_container_rm___all(){
    {
        local id=""
        local name
        while read -r id && read -r name; do
            webtop:info "Removing container [name=$name] [id=$id]"
            ___x_cmd docker -- rm "$id"
        done
    } <<A
$(___x_cmd_webtop_container_foreach exited)
A

    [ -n "$id" ] || webtop:info "No contaniner to remove."
    ! ___x_cmd_runmode_allow_chatty || ___x_cmd webtop ps
}
