_alpm-pkginfo() {
    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__pkginfo"
                ;;
            alpm__pkginfo,create)
                cmd="alpm__pkginfo__create"
                ;;
            alpm__pkginfo,format)
                cmd="alpm__pkginfo__format"
                ;;
            alpm__pkginfo,help)
                cmd="alpm__pkginfo__help"
                ;;
            alpm__pkginfo,validate)
                cmd="alpm__pkginfo__validate"
                ;;
            alpm__pkginfo__create,help)
                cmd="alpm__pkginfo__create__help"
                ;;
            alpm__pkginfo__create,v1)
                cmd="alpm__pkginfo__create__v1"
                ;;
            alpm__pkginfo__create,v2)
                cmd="alpm__pkginfo__create__v2"
                ;;
            alpm__pkginfo__create__help,help)
                cmd="alpm__pkginfo__create__help__help"
                ;;
            alpm__pkginfo__create__help,v1)
                cmd="alpm__pkginfo__create__help__v1"
                ;;
            alpm__pkginfo__create__help,v2)
                cmd="alpm__pkginfo__create__help__v2"
                ;;
            alpm__pkginfo__help,create)
                cmd="alpm__pkginfo__help__create"
                ;;
            alpm__pkginfo__help,format)
                cmd="alpm__pkginfo__help__format"
                ;;
            alpm__pkginfo__help,help)
                cmd="alpm__pkginfo__help__help"
                ;;
            alpm__pkginfo__help,validate)
                cmd="alpm__pkginfo__help__validate"
                ;;
            alpm__pkginfo__help__create,v1)
                cmd="alpm__pkginfo__help__create__v1"
                ;;
            alpm__pkginfo__help__create,v2)
                cmd="alpm__pkginfo__help__create__v2"
                ;;
            *)
                ;;
        esac
    done

    case "${cmd}" in
        alpm__pkginfo)
            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__pkginfo__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__pkginfo__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__pkginfo__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__pkginfo__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__pkginfo__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__pkginfo__create__v1)
            opts="-h --pkgname --pkgbase --pkgver --pkgdesc --url --builddate --packager --size --arch --license --replaces --group --conflict --provides --backup --depend --optdepend --makedepend --checkdepend --help [FILE]"
            if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then
                COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
                return 0
            fi
            case "${prev}" in
                --pkgname)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --pkgbase)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --pkgver)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --pkgdesc)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --url)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --builddate)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --packager)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --size)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --arch)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --license)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --replaces)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --group)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --conflict)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --provides)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --backup)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --depend)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --optdepend)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --makedepend)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --checkdepend)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                *)
                    COMPREPLY=()
                    ;;
            esac
            COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
            return 0
            ;;
        alpm__pkginfo__create__v2)
            opts="-h --pkgname --pkgbase --pkgver --pkgdesc --url --builddate --packager --size --arch --license --replaces --group --conflict --provides --backup --depend --optdepend --makedepend --checkdepend --xdata --help [FILE]"
            if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then
                COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
                return 0
            fi
            case "${prev}" in
                --pkgname)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --pkgbase)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --pkgver)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --pkgdesc)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --url)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --builddate)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --packager)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --size)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --arch)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --license)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --replaces)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --group)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --conflict)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --provides)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --backup)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --depend)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --optdepend)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --makedepend)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --checkdepend)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --xdata)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                *)
                    COMPREPLY=()
                    ;;
            esac
            COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
            return 0
            ;;
        alpm__pkginfo__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__pkginfo__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__pkginfo__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__pkginfo__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__pkginfo__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__pkginfo__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__pkginfo__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__pkginfo__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__pkginfo__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-pkginfo -o nosort -o bashdefault -o default alpm-pkginfo
else
    complete -F _alpm-pkginfo -o bashdefault -o default alpm-pkginfo
fi
