obd.sh 1.8 KB
Newer Older
O
oceanbase-admin 已提交
1 2 3 4 5 6 7 8
#!/bin/bash

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

function _obd_complete_func   
{  
R
Rongfeng Fu 已提交
9
    local cur prev cmd obd_cmd cluster_cmd tenant_cmd mirror_cmd test_cmd
O
oceanbase-admin 已提交
10 11 12
    COMPREPLY=()
    cur="${COMP_WORDS[COMP_CWORD]}"
    prev="${COMP_WORDS[COMP_CWORD-1]}"
R
Rongfeng Fu 已提交
13 14 15
    obd_cmd="mirror cluster test update repo"
    cluster_cmd="autodeploy tenant start deploy redeploy restart reload destroy stop edit-config list display upgrade"
    tenant_cmd="create drop"
O
oceanbase-admin 已提交
16
    mirror_cmd="clone create list update"
R
Rongfeng Fu 已提交
17
    repo_cmd="list"
R
Rongfeng Fu 已提交
18
    test_cmd="mysqltest sysbench tpch"
O
oceanbase-admin 已提交
19 20 21 22 23
    if [[ ${cur} == * ]] ; then
        case "${prev}" in
            obd);&
            test);&
            cluster);&
R
Rongfeng Fu 已提交
24 25 26
            tenant);&
            mirror);&
            repo)
O
oceanbase-admin 已提交
27 28 29 30 31 32 33 34 35 36 37 38
                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}) )
            ;;
R
Rongfeng Fu 已提交
39 40 41 42 43 44 45 46 47 48 49 50
            *)
                if [ "$prev" == "list" ]; then
                    return 0
                else
                    prev="${COMP_WORDS[COMP_CWORD-2]}"
                    obd_home=${OBD_HOME:-~/.obd}
                    if [[ "$prev" == "cluster" || "$prev" == "test" || "$prev" == "tenant" ]]; then
                        res=`ls -p $obd_home/cluster 2>/dev/null | sed "s#/##"`
                        compopt -o nospace
                        COMPREPLY=( $(compgen -o filenames -W "${res}" -- ${cur}) )
                    fi
                fi
O
oceanbase-admin 已提交
51 52 53 54 55
        esac
        return 0
    fi
}