__contains_word () {
    local w word=$1; shift
    for w in "$@"; do
        [[ $w = "$word" ]] && return
    done
}

_kylin-sysinfo() {
    local i verb comps custom
    local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]}

    local -A VERBS=(
        [VERSION]='version'
        [HELP]='--help'
    )

    for ((i=0; i < COMP_CWORD; i++)); do
        if __contains_word "${COMP_WORDS[i]}" ${VERBS[*]}; then
            verb=${COMP_WORDS[i]}
            break
        fi
    done

    if [[ -z $verb ]]; then
        comps=${VERBS[*]}
    elif __contains_word "$verb" ${VERBS[VERSION]}; then
        comps='--production --minor --alias --serial --all --customization --major'
    elif __contains_word "$verb" ${VERBS[HELP]}; then
        comps=''
    fi

    COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
    return 0
}

complete -F _kylin-sysinfo kylin-sysinfo
