_alpm-buildinfo() {
    local i cur prev opts cmd
    COMPREPLY=()
    if [[ "${BASH_VERSINFO[0]}" -ge 4 ]]; then
        cur="$2"
    else
        cur="${COMP_WORDS[COMP_CWORD]}"
    fi
    prev="$3"
    cmd=""
    opts=""

    for i in "${COMP_WORDS[@]:0:COMP_CWORD}"
    do
        case "${cmd},${i}" in
            ",$1")
                cmd="alpm__buildinfo"
                ;;
            alpm__buildinfo,create)
                cmd="alpm__buildinfo__create"
                ;;
            alpm__buildinfo,format)
                cmd="alpm__buildinfo__format"
                ;;
            alpm__buildinfo,help)
                cmd="alpm__buildinfo__help"
                ;;
            alpm__buildinfo,validate)
                cmd="alpm__buildinfo__validate"
                ;;
            alpm__buildinfo__create,help)
                cmd="alpm__buildinfo__create__help"
                ;;
            alpm__buildinfo__create,v1)
                cmd="alpm__buildinfo__create__v1"
                ;;
            alpm__buildinfo__create,v2)
                cmd="alpm__buildinfo__create__v2"
                ;;
            alpm__buildinfo__create__help,help)
                cmd="alpm__buildinfo__create__help__help"
                ;;
            alpm__buildinfo__create__help,v1)
                cmd="alpm__buildinfo__create__help__v1"
                ;;
            alpm__buildinfo__create__help,v2)
                cmd="alpm__buildinfo__create__help__v2"
                ;;
            alpm__buildinfo__help,create)
                cmd="alpm__buildinfo__help__create"
                ;;
            alpm__buildinfo__help,format)
                cmd="alpm__buildinfo__help__format"
                ;;
            alpm__buildinfo__help,help)
                cmd="alpm__buildinfo__help__help"
                ;;
            alpm__buildinfo__help,validate)
                cmd="alpm__buildinfo__help__validate"
                ;;
            alpm__buildinfo__help__create,v1)
                cmd="alpm__buildinfo__help__create__v1"
                ;;
            alpm__buildinfo__help__create,v2)
                cmd="alpm__buildinfo__help__create__v2"
                ;;
            *)
                ;;
        esac
    done

    case "${cmd}" in
        alpm__buildinfo)
            opts="-h -V --help --version create validate format help"
            if [[ ${cur} == -* || ${COMP_CWORD} -eq 1 ]] ; then
                COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
                return 0
            fi
            case "${prev}" in
                *)
                    COMPREPLY=()
                    ;;
            esac
            COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
            return 0
            ;;
        alpm__buildinfo__create)
            opts="-h --help v1 v2 help"
            if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
                COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
                return 0
            fi
            case "${prev}" in
                *)
                    COMPREPLY=()
                    ;;
            esac
            COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
            return 0
            ;;
        alpm__buildinfo__create__help)
            opts="v1 v2 help"
            if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then
                COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
                return 0
            fi
            case "${prev}" in
                *)
                    COMPREPLY=()
                    ;;
            esac
            COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
            return 0
            ;;
        alpm__buildinfo__create__help__help)
            opts=""
            if [[ ${cur} == -* || ${COMP_CWORD} -eq 4 ]] ; then
                COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
                return 0
            fi
            case "${prev}" in
                *)
                    COMPREPLY=()
                    ;;
            esac
            COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
            return 0
            ;;
        alpm__buildinfo__create__help__v1)
            opts=""
            if [[ ${cur} == -* || ${COMP_CWORD} -eq 4 ]] ; then
                COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
                return 0
            fi
            case "${prev}" in
                *)
                    COMPREPLY=()
                    ;;
            esac
            COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
            return 0
            ;;
        alpm__buildinfo__create__help__v2)
            opts=""
            if [[ ${cur} == -* || ${COMP_CWORD} -eq 4 ]] ; then
                COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
                return 0
            fi
            case "${prev}" in
                *)
                    COMPREPLY=()
                    ;;
            esac
            COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
            return 0
            ;;
        alpm__buildinfo__create__v1)
            opts="-h --builddate --builddir --buildenv --installed --options --packager --pkgarch --pkgbase --pkgbuild-sha256sum --pkgname --pkgver --help [FILE]"
            if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then
                COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
                return 0
            fi
            case "${prev}" in
                --builddate)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --builddir)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --buildenv)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --installed)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --options)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --packager)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --pkgarch)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --pkgbase)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --pkgbuild-sha256sum)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --pkgname)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --pkgver)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                *)
                    COMPREPLY=()
                    ;;
            esac
            COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
            return 0
            ;;
        alpm__buildinfo__create__v2)
            opts="-h --builddate --builddir --buildenv --installed --options --packager --pkgarch --pkgbase --pkgbuild-sha256sum --pkgname --pkgver --startdir --buildtool --buildtoolver --help [FILE]"
            if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then
                COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
                return 0
            fi
            case "${prev}" in
                --builddate)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --builddir)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --buildenv)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --installed)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --options)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --packager)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --pkgarch)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --pkgbase)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --pkgbuild-sha256sum)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --pkgname)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --pkgver)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --startdir)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --buildtool)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --buildtoolver)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                *)
                    COMPREPLY=()
                    ;;
            esac
            COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
            return 0
            ;;
        alpm__buildinfo__format)
            opts="-s -o -p -h --schema --output-format --pretty --help [FILE]"
            if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
                COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
                return 0
            fi
            case "${prev}" in
                --schema)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                -s)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --output-format)
                    COMPREPLY=($(compgen -W "json" -- "${cur}"))
                    return 0
                    ;;
                -o)
                    COMPREPLY=($(compgen -W "json" -- "${cur}"))
                    return 0
                    ;;
                *)
                    COMPREPLY=()
                    ;;
            esac
            COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
            return 0
            ;;
        alpm__buildinfo__help)
            opts="create validate format help"
            if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
                COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
                return 0
            fi
            case "${prev}" in
                *)
                    COMPREPLY=()
                    ;;
            esac
            COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
            return 0
            ;;
        alpm__buildinfo__help__create)
            opts="v1 v2"
            if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then
                COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
                return 0
            fi
            case "${prev}" in
                *)
                    COMPREPLY=()
                    ;;
            esac
            COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
            return 0
            ;;
        alpm__buildinfo__help__create__v1)
            opts=""
            if [[ ${cur} == -* || ${COMP_CWORD} -eq 4 ]] ; then
                COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
                return 0
            fi
            case "${prev}" in
                *)
                    COMPREPLY=()
                    ;;
            esac
            COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
            return 0
            ;;
        alpm__buildinfo__help__create__v2)
            opts=""
            if [[ ${cur} == -* || ${COMP_CWORD} -eq 4 ]] ; then
                COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
                return 0
            fi
            case "${prev}" in
                *)
                    COMPREPLY=()
                    ;;
            esac
            COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
            return 0
            ;;
        alpm__buildinfo__help__format)
            opts=""
            if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then
                COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
                return 0
            fi
            case "${prev}" in
                *)
                    COMPREPLY=()
                    ;;
            esac
            COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
            return 0
            ;;
        alpm__buildinfo__help__help)
            opts=""
            if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then
                COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
                return 0
            fi
            case "${prev}" in
                *)
                    COMPREPLY=()
                    ;;
            esac
            COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
            return 0
            ;;
        alpm__buildinfo__help__validate)
            opts=""
            if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then
                COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
                return 0
            fi
            case "${prev}" in
                *)
                    COMPREPLY=()
                    ;;
            esac
            COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
            return 0
            ;;
        alpm__buildinfo__validate)
            opts="-s -h --schema --help [FILE]"
            if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
                COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
                return 0
            fi
            case "${prev}" in
                --schema)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                -s)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                *)
                    COMPREPLY=()
                    ;;
            esac
            COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
            return 0
            ;;
    esac
}

if [[ "${BASH_VERSINFO[0]}" -eq 4 && "${BASH_VERSINFO[1]}" -ge 4 || "${BASH_VERSINFO[0]}" -gt 4 ]]; then
    complete -F _alpm-buildinfo -o nosort -o bashdefault -o default alpm-buildinfo
else
    complete -F _alpm-buildinfo -o bashdefault -o default alpm-buildinfo
fi
