obd.sh 2.0 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 devmode_cmd
O
oceanbase-admin 已提交
10 11 12
    COMPREPLY=()
    cur="${COMP_WORDS[COMP_CWORD]}"
    prev="${COMP_WORDS[COMP_CWORD-1]}"
R
Rongfeng Fu 已提交
13
    obd_cmd="mirror cluster test update repo"
R
Rongfeng Fu 已提交
14
    cluster_cmd="autodeploy tenant start deploy redeploy restart reload destroy stop edit-config list display upgrade chst check4ocp"
R
Rongfeng Fu 已提交
15
    tenant_cmd="create drop"
R
Rongfeng Fu 已提交
16
    mirror_cmd="clone create list update enable disable"
R
Rongfeng Fu 已提交
17
    repo_cmd="list"
R
Rongfeng Fu 已提交
18
    test_cmd="mysqltest sysbench tpch"
R
Rongfeng Fu 已提交
19 20 21 22 23
    if [ -f "${OBD_HOME:-"$HOME"}/.obd/.dev_mode" ]; then
        obd_cmd="$obd_cmd devmode"
        devmode_cmd="enable disable"
    fi

O
oceanbase-admin 已提交
24 25 26 27 28
    if [[ ${cur} == * ]] ; then
        case "${prev}" in
            obd);&
            test);&
            cluster);&
R
Rongfeng Fu 已提交
29 30
            tenant);&
            mirror);&
R
Rongfeng Fu 已提交
31
            devmode);&
R
Rongfeng Fu 已提交
32
            repo)
O
oceanbase-admin 已提交
33 34 35 36 37 38 39 40
                cmd=$(eval echo \$"${prev}_cmd")
                COMPREPLY=( $(compgen -W "${cmd}" -- ${cur}) )
            ;;
            clone);&
            -p|--path);&
            -c|--config)
                filename=${cur##*/}
                dirname=${cur%*$filename}
R
Rongfeng Fu 已提交
41
                res=`ls -p $dirname 2>/dev/null | sed "s#^#$dirname#"`
O
oceanbase-admin 已提交
42 43 44
                compopt -o nospace
                COMPREPLY=( $(compgen -o filenames -W "${res}" -- ${cur}) )
            ;;
R
Rongfeng Fu 已提交
45 46 47 48 49
            *)
                if [ "$prev" == "list" ]; then
                    return 0
                else
                    prev="${COMP_WORDS[COMP_CWORD-2]}"
R
Rongfeng Fu 已提交
50
                    obd_home=${OBD_HOME:-~}
R
Rongfeng Fu 已提交
51
                    if [[ "$prev" == "cluster" || "$prev" == "test" || "$prev" == "tenant" ]]; then
R
Rongfeng Fu 已提交
52
                        res=`ls -p $obd_home/.obd/cluster 2>/dev/null | sed "s#/##"`
R
Rongfeng Fu 已提交
53 54 55 56
                        compopt -o nospace
                        COMPREPLY=( $(compgen -o filenames -W "${res}" -- ${cur}) )
                    fi
                fi
O
oceanbase-admin 已提交
57 58 59 60 61
        esac
        return 0
    fi
}