_espflash() {
    local i cur prev opts cmd
    COMPREPLY=()
    cur="${COMP_WORDS[COMP_CWORD]}"
    prev="${COMP_WORDS[COMP_CWORD-1]}"
    cmd=""
    opts=""

    for i in ${COMP_WORDS[@]}
    do
        case "${cmd},${i}" in
            ",$1")
                cmd="espflash"
                ;;
            espflash,board-info)
                cmd="espflash__board__info"
                ;;
            espflash,completions)
                cmd="espflash__completions"
                ;;
            espflash,erase-flash)
                cmd="espflash__erase__flash"
                ;;
            espflash,erase-parts)
                cmd="espflash__erase__parts"
                ;;
            espflash,erase-region)
                cmd="espflash__erase__region"
                ;;
            espflash,flash)
                cmd="espflash__flash"
                ;;
            espflash,help)
                cmd="espflash__help"
                ;;
            espflash,monitor)
                cmd="espflash__monitor"
                ;;
            espflash,partition-table)
                cmd="espflash__partition__table"
                ;;
            espflash,save-image)
                cmd="espflash__save__image"
                ;;
            espflash,write-bin)
                cmd="espflash__write__bin"
                ;;
            espflash__help,board-info)
                cmd="espflash__help__board__info"
                ;;
            espflash__help,completions)
                cmd="espflash__help__completions"
                ;;
            espflash__help,erase-flash)
                cmd="espflash__help__erase__flash"
                ;;
            espflash__help,erase-parts)
                cmd="espflash__help__erase__parts"
                ;;
            espflash__help,erase-region)
                cmd="espflash__help__erase__region"
                ;;
            espflash__help,flash)
                cmd="espflash__help__flash"
                ;;
            espflash__help,help)
                cmd="espflash__help__help"
                ;;
            espflash__help,monitor)
                cmd="espflash__help__monitor"
                ;;
            espflash__help,partition-table)
                cmd="espflash__help__partition__table"
                ;;
            espflash__help,save-image)
                cmd="espflash__help__save__image"
                ;;
            espflash__help,write-bin)
                cmd="espflash__help__write__bin"
                ;;
            *)
                ;;
        esac
    done

    case "${cmd}" in
        espflash)
            opts="-h -V --help --version board-info completions erase-flash erase-parts erase-region flash monitor partition-table save-image write-bin 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
            ;;
        espflash__board__info)
            opts="-b -p -h -V --baud --port --no-stub --help --version"
            if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
                COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
                return 0
            fi
            case "${prev}" in
                --baud)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                -b)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --port)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                -p)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                *)
                    COMPREPLY=()
                    ;;
            esac
            COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
            return 0
            ;;
        espflash__completions)
            opts="-h -V --help --version bash elvish fish powershell zsh"
            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
            ;;
        espflash__erase__flash)
            opts="-b -p -h -V --baud --port --no-stub --help --version"
            if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
                COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
                return 0
            fi
            case "${prev}" in
                --baud)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                -b)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --port)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                -p)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                *)
                    COMPREPLY=()
                    ;;
            esac
            COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
            return 0
            ;;
        espflash__erase__parts)
            opts="-b -p -h -V --baud --port --no-stub --partition-table --help --version [LABELS]..."
            if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
                COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
                return 0
            fi
            case "${prev}" in
                --baud)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                -b)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --port)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                -p)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --partition-table)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                *)
                    COMPREPLY=()
                    ;;
            esac
            COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
            return 0
            ;;
        espflash__erase__region)
            opts="-b -p -h -V --baud --port --no-stub --help --version <OFFSET> <SIZE>"
            if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
                COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
                return 0
            fi
            case "${prev}" in
                --baud)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                -b)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --port)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                -p)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                *)
                    COMPREPLY=()
                    ;;
            esac
            COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
            return 0
            ;;
        espflash__flash)
            opts="-b -p -f -m -s -M -h -V --baud --port --no-stub --flash-freq --flash-mode --flash-size --bootloader --erase-parts --erase-data-parts --format --monitor --monitor-baud --partition-table --ram --help --version <IMAGE>"
            if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
                COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
                return 0
            fi
            case "${prev}" in
                --baud)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                -b)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --port)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                -p)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --flash-freq)
                    COMPREPLY=($(compgen -W "12mhz 15mhz 16mhz 20mhz 24mhz 26mhz 30mhz 40mhz 48mhz 60mhz 80mhz" -- "${cur}"))
                    return 0
                    ;;
                -f)
                    COMPREPLY=($(compgen -W "12mhz 15mhz 16mhz 20mhz 24mhz 26mhz 30mhz 40mhz 48mhz 60mhz 80mhz" -- "${cur}"))
                    return 0
                    ;;
                --flash-mode)
                    COMPREPLY=($(compgen -W "qio qout dio dout" -- "${cur}"))
                    return 0
                    ;;
                -m)
                    COMPREPLY=($(compgen -W "qio qout dio dout" -- "${cur}"))
                    return 0
                    ;;
                --flash-size)
                    COMPREPLY=($(compgen -W "256kb 512kb 1mb 2mb 4mb 8mb 16mb 32mb 64mb 128mb 256mb" -- "${cur}"))
                    return 0
                    ;;
                -s)
                    COMPREPLY=($(compgen -W "256kb 512kb 1mb 2mb 4mb 8mb 16mb 32mb 64mb 128mb 256mb" -- "${cur}"))
                    return 0
                    ;;
                --bootloader)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --erase-parts)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --erase-data-parts)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --format)
                    COMPREPLY=($(compgen -W "esp-bootloader direct-boot" -- "${cur}"))
                    return 0
                    ;;
                --monitor-baud)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --partition-table)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                *)
                    COMPREPLY=()
                    ;;
            esac
            COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
            return 0
            ;;
        espflash__help)
            opts="board-info completions erase-flash erase-parts erase-region flash monitor partition-table save-image write-bin 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
            ;;
        espflash__help__board__info)
            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
            ;;
        espflash__help__completions)
            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
            ;;
        espflash__help__erase__flash)
            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
            ;;
        espflash__help__erase__parts)
            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
            ;;
        espflash__help__erase__region)
            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
            ;;
        espflash__help__flash)
            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
            ;;
        espflash__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
            ;;
        espflash__help__monitor)
            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
            ;;
        espflash__help__partition__table)
            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
            ;;
        espflash__help__save__image)
            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
            ;;
        espflash__help__write__bin)
            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
            ;;
        espflash__monitor)
            opts="-e -b -p -h -V --elf --baud --port --no-stub --help --version"
            if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
                COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
                return 0
            fi
            case "${prev}" in
                --elf)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                -e)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --baud)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                -b)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --port)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                -p)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                *)
                    COMPREPLY=()
                    ;;
            esac
            COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
            return 0
            ;;
        espflash__partition__table)
            opts="-o -h -V --output --to-binary --to-csv --help --version <FILE>"
            if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
                COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
                return 0
            fi
            case "${prev}" in
                --output)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                -o)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                *)
                    COMPREPLY=()
                    ;;
            esac
            COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
            return 0
            ;;
        espflash__save__image)
            opts="-f -m -s -T -P -h -V --format --flash-freq --flash-mode --flash-size --bootloader --chip --merge --partition-table --skip-padding --help --version <IMAGE> <FILE>"
            if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
                COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
                return 0
            fi
            case "${prev}" in
                --format)
                    COMPREPLY=($(compgen -W "esp-bootloader direct-boot" -- "${cur}"))
                    return 0
                    ;;
                --flash-freq)
                    COMPREPLY=($(compgen -W "12mhz 15mhz 16mhz 20mhz 24mhz 26mhz 30mhz 40mhz 48mhz 60mhz 80mhz" -- "${cur}"))
                    return 0
                    ;;
                -f)
                    COMPREPLY=($(compgen -W "12mhz 15mhz 16mhz 20mhz 24mhz 26mhz 30mhz 40mhz 48mhz 60mhz 80mhz" -- "${cur}"))
                    return 0
                    ;;
                --flash-mode)
                    COMPREPLY=($(compgen -W "qio qout dio dout" -- "${cur}"))
                    return 0
                    ;;
                -m)
                    COMPREPLY=($(compgen -W "qio qout dio dout" -- "${cur}"))
                    return 0
                    ;;
                --flash-size)
                    COMPREPLY=($(compgen -W "256kb 512kb 1mb 2mb 4mb 8mb 16mb 32mb 64mb 128mb 256mb" -- "${cur}"))
                    return 0
                    ;;
                -s)
                    COMPREPLY=($(compgen -W "256kb 512kb 1mb 2mb 4mb 8mb 16mb 32mb 64mb 128mb 256mb" -- "${cur}"))
                    return 0
                    ;;
                --bootloader)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --chip)
                    COMPREPLY=($(compgen -W "esp32 esp32c2 esp32c3 esp32c6 esp32s2 esp32s3 esp32h2 esp8266" -- "${cur}"))
                    return 0
                    ;;
                --partition-table)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                -T)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                *)
                    COMPREPLY=()
                    ;;
            esac
            COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
            return 0
            ;;
        espflash__write__bin)
            opts="-b -p -h -V --baud --port --no-stub --help --version <ADDR> <BIN_FILE>"
            if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
                COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
                return 0
            fi
            case "${prev}" in
                --baud)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                -b)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --port)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                -p)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                *)
                    COMPREPLY=()
                    ;;
            esac
            COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
            return 0
            ;;
    esac
}

complete -F _espflash -o nosort -o bashdefault -o default espflash
