obd.sh 1.1 KB
Newer Older
O
oceanbase-admin 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
#!/bin/bash

if [ -n "$BASH_VERSION" ]; then
    complete -F _obd_complete_func obd
fi

function _obd_complete_func   
{  
    local cur prev cmd obd_cmd cluster_cmd mirror_cmd test_cmd
    COMPREPLY=()
    cur="${COMP_WORDS[COMP_CWORD]}"
    prev="${COMP_WORDS[COMP_CWORD-1]}"
    obd_cmd="mirror cluster test"
    cluster_cmd="start deploy redeploy restart reload destroy stop edit-config list display"
    mirror_cmd="clone create list update"
    test_cmd="mysqltest"
    if [[ ${cur} == * ]] ; then
        case "${prev}" in
            obd);&
            test);&
            cluster);&
            mirror)
                cmd=$(eval echo \$"${prev}_cmd")
                COMPREPLY=( $(compgen -W "${cmd}" -- ${cur}) )
            ;;
            clone);&
            -p|--path);&
            -c|--config)
                filename=${cur##*/}
                dirname=${cur%*$filename}
                res=`ls -a -p $dirname 2>/dev/null | sed "s#^#$dirname#"`
                compopt -o nospace
                COMPREPLY=( $(compgen -o filenames -W "${res}" -- ${cur}) )
            ;;
        esac
        return 0
    fi
}