#!bash

_dog_cluster()
{
    local opts
    opts="info format shutdown snapshot recover reweight check"

    case "$1" in
        info)
            _dog_cluster_info
            ;;
        format)
            _dog_cluster_format
            ;;
        shutdown)
            _dog_cluster_shutdown
            ;;
        snapshot)
            _dog_cluster_snapshot
            ;;
        recover)
            _dog_cluster_recover
            ;;
        reweight)
            _dog_cluster_reweight
            ;;
        check)
            _dog_cluster_check
            ;;
        "")
            COMPREPLY=($( compgen \
                -W "${opts}" \
                -- "${COMP_WORDS[COMP_CWORD]}" ))
            ;;
        *)
            COMPREPLY=()
            ;;
    esac
}

_dog_cluster_info()
{
    local cur
    cur="${COMP_WORDS[COMP_CWORD]}"

    case "$cur" in
        -*)
            COMPREPLY=(${COMPREPLY[@]} \
                $( compgen \
                -W "-a --address -p --port -r --raw -h --help -s --backend" \
                -- ${cur} ))
            ;;
        *)
            COMPREPLY=($( compgen -W "" -- ${cur} ))
            ;;
    esac
}

_dog_cluster_format()
{
    local cur
    cur="${COMP_WORDS[COMP_CWORD]}"

    case "$cur" in
        -*)
            COMPREPLY=(${COMPREPLY[@]} \
                $( compgen \
                -W "-b --store -c --copies -t --strict -a --address -p --port -h --help" \
                -- ${cur} ))
            ;;
        *)
            COMPREPLY=($( compgen -W "" -- ${cur} ))
            ;;
    esac
}

_dog_cluster_shutdown()
{
    local cur
    cur="${COMP_WORDS[COMP_CWORD]}"

    case "$cur" in
        -*)
            COMPREPLY=(${COMPREPLY[@]} \
                $( compgen \
                -W "-a --address -p --port -h --help" \
                -- ${cur} ))
            ;;
        *)
            COMPREPLY=($( compgen -W "" -- ${cur} ))
            ;;
    esac
}

_dog_cluster_snapshot()
{
    local cur
    cur="${COMP_WORDS[COMP_CWORD]}"

    case "$cur" in
        -*)
            COMPREPLY=(${COMPREPLY[@]} \
                $( compgen \
                -W "-a --address -p --port -h --help" \
                -- ${cur} ))
            ;;
        *)
            COMPREPLY=($( compgen -W "save list load" -- ${cur} ))
            ;;
    esac
}

_dog_cluster_recover()
{
    local cur
    cur="${COMP_WORDS[COMP_CWORD]}"

    case "$cur" in
        -*)
            COMPREPLY=(${COMPREPLY[@]} \
                $( compgen \
                -W "-a --address -f --force -p --port -h --help" \
                -- ${cur} ))
            ;;
        *)
            COMPREPLY=($( compgen -W "force enable disable" -- ${cur} ))
            ;;
    esac
}

_dog_cluster_reweight()
{
    local cur
    cur="${COMP_WORDS[COMP_CWORD]}"

    case "$cur" in
        -*)
            COMPREPLY=(${COMPREPLY[@]} \
                $( compgen \
                -W "-a --address -p --port -h --help" \
                -- ${cur} ))
            ;;
        *)
            COMPREPLY=($( compgen -W "" -- ${cur} ))
            ;;
    esac
}

_dog_cluster_check()
{
    local cur
    cur="${COMP_WORDS[COMP_CWORD]}"

    case "$cur" in
        -*)
            COMPREPLY=(${COMPREPLY[@]} \
                $( compgen \
                -W "-a --address -p --port -h --help" \
                -- ${cur} ))
            ;;
        *)
            COMPREPLY=($( compgen -W "" -- ${cur} ))
            ;;
    esac
}

_dog_node()
{
    local opts
    opts="kill list info recovery md stat log"

    case "$1" in
        kill)
            _dog_node_kill
            ;;
        list)
            _dog_node_list
            ;;
        info)
            _dog_node_info
            ;;
        recovery)
            _dog_node_recovery
            ;;
        md)
            _dog_node_md
            ;;
        stat)
            _dog_node_stat
            ;;
        log)
            _dog_node_log
            ;;
        "")
            COMPREPLY=($( compgen \
                -W "${opts}" \
                -- "${COMP_WORDS[COMP_CWORD]}" ))
            ;;
        *)
            COMPREPLY=()
            ;;
    esac
}

_dog_node_kill()
{
    local cur
    cur="${COMP_WORDS[COMP_CWORD]}"

    case "$cur" in
        -*)
            COMPREPLY=(${COMPREPLY[@]} \
                $( compgen \
                -W "-a --address -p --port -r --raw -h --help -l --local" \
                -- ${cur} ))
            ;;
        *)
            COMPREPLY=($( compgen -W "" -- ${cur} ))
            ;;
    esac
}

_dog_node_list()
{
    local cur
    cur="${COMP_WORDS[COMP_CWORD]}"

    case "$cur" in
        -*)
            COMPREPLY=(${COMPREPLY[@]} \
                $( compgen \
                -W "-a --address -p --port -r --raw -h --help" \
                -- ${cur} ))
            ;;
        *)
            COMPREPLY=($( compgen -W "" -- ${cur} ))
            ;;
    esac
}

_dog_node_info()
{
    local cur
    cur="${COMP_WORDS[COMP_CWORD]}"

    case "$cur" in
        -*)
            COMPREPLY=(${COMPREPLY[@]} \
                $( compgen \
                -W "-a --address -p --port -r --raw -h --help" \
                -- ${cur} ))
            ;;
        *)
            COMPREPLY=($( compgen -W "" -- ${cur} ))
            ;;
    esac
}

_dog_node_recovery()
{
    local cur
    cur="${COMP_WORDS[COMP_CWORD]}"

    case "$cur" in
        -*)
            COMPREPLY=(${COMPREPLY[@]} \
                $( compgen \
                -W "-a --address -p --port -h --help -P --progress -r --raw" \
                -- ${cur} ))
            ;;
        *)
            COMPREPLY=($( compgen -W "" -- ${cur} ))
            ;;
    esac
}

_dog_node_md()
{
    local cur
    cur="${COMP_WORDS[COMP_CWORD]}"

    case "$cur" in
        -*)
            COMPREPLY=(${COMPREPLY[@]} \
                $( compgen \
                -W "-a --address -p --port -r --raw -A --all -h --help" \
                -- ${cur} ))
            ;;
        *)
            COMPREPLY=($( compgen -W "info plug unplug" -- ${cur} ))
            ;;
    esac
}

_dog_node_stat()
{
    local cur
    cur="${COMP_WORDS[COMP_CWORD]}"

    case "$cur" in
        -*)
            COMPREPLY=(${COMPREPLY[@]} \
                $( compgen \
                -W "-a --address -p --port -r --raw -w --watch -h --help" \
                -- ${cur} ))
            ;;
        *)
            COMPREPLY=($( compgen -W "" -- ${cur} ))
            ;;
    esac
}

_dog_node_log()
{
    local cur
    cur="${COMP_WORDS[COMP_CWORD]}"

    case "$cur" in
        -*)
            COMPREPLY=(${COMPREPLY[@]} \
                $( compgen \
                -W "-a --address -p --port -h --help" \
                -- ${cur} ))
            ;;
        *)
            COMPREPLY=($( compgen -W "level" -- ${cur} ))
            ;;
    esac
}

_dog_vdi()
{
    local opts
    opts="check create snapshot clone delete rollback list tree graph object track setattr getattr resize read write backup restore cache"

    case "$1" in
        check)
            _dog_vdi_check
            ;;
        create)
            _dog_vdi_create
            ;;
        snapshot)
            _dog_vdi_snapshot
            ;;
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              