#compdef espflash

autoload -U is-at-least

_espflash() {
    typeset -A opt_args
    typeset -a _arguments_options
    local ret=1

    if is-at-least 5.2; then
        _arguments_options=(-s -S -C)
    else
        _arguments_options=(-s -C)
    fi

    local context curcontext="$curcontext" state line
    _arguments "${_arguments_options[@]}" \
'-h[Print help]' \
'--help[Print help]' \
'-V[Print version]' \
'--version[Print version]' \
":: :_espflash_commands" \
"*::: :->espflash" \
&& ret=0
    case $state in
    (espflash)
        words=($line[1] "${words[@]}")
        (( CURRENT += 1 ))
        curcontext="${curcontext%:*:*}:espflash-command-$line[1]:"
        case $line[1] in
            (board-info)
_arguments "${_arguments_options[@]}" \
'-b+[Baud rate at which to communicate with target device]:BAUD: ' \
'--baud=[Baud rate at which to communicate with target device]:BAUD: ' \
'-p+[Serial port connected to target device]:PORT: ' \
'--port=[Serial port connected to target device]:PORT: ' \
'--no-stub[Do not use the RAM stub for loading]' \
'-h[Print help (see more with '\''--help'\'')]' \
'--help[Print help (see more with '\''--help'\'')]' \
'-V[Print version]' \
'--version[Print version]' \
&& ret=0
;;
(completions)
_arguments "${_arguments_options[@]}" \
'-h[Print help (see more with '\''--help'\'')]' \
'--help[Print help (see more with '\''--help'\'')]' \
'-V[Print version]' \
'--version[Print version]' \
':shell -- Shell to generate completions for:(bash elvish fish powershell zsh)' \
&& ret=0
;;
(erase-flash)
_arguments "${_arguments_options[@]}" \
'-b+[Baud rate at which to communicate with target device]:BAUD: ' \
'--baud=[Baud rate at which to communicate with target device]:BAUD: ' \
'-p+[Serial port connected to target device]:PORT: ' \
'--port=[Serial port connected to target device]:PORT: ' \
'--no-stub[Do not use the RAM stub for loading]' \
'-h[Print help]' \
'--help[Print help]' \
'-V[Print version]' \
'--version[Print version]' \
&& ret=0
;;
(erase-parts)
_arguments "${_arguments_options[@]}" \
'-b+[Baud rate at which to communicate with target device]:BAUD: ' \
'--baud=[Baud rate at which to communicate with target device]:BAUD: ' \
'-p+[Serial port connected to target device]:PORT: ' \
'--port=[Serial port connected to target device]:PORT: ' \
'--partition-table=[Input partition table]:FILE:_files' \
'--no-stub[Do not use the RAM stub for loading]' \
'-h[Print help]' \
'--help[Print help]' \
'-V[Print version]' \
'--version[Print version]' \
'*::erase_parts -- Labels of the partitions to be erased:' \
&& ret=0
;;
(erase-region)
_arguments "${_arguments_options[@]}" \
'-b+[Baud rate at which to communicate with target device]:BAUD: ' \
'--baud=[Baud rate at which to communicate with target device]:BAUD: ' \
'-p+[Serial port connected to target device]:PORT: ' \
'--port=[Serial port connected to target device]:PORT: ' \
'--no-stub[Do not use the RAM stub for loading]' \
'-h[Print help]' \
'--help[Print help]' \
'-V[Print version]' \
'--version[Print version]' \
':addr -- Offset to start erasing from:' \
':size -- Size of the region to erase:' \
&& ret=0
;;
(flash)
_arguments "${_arguments_options[@]}" \
'-b+[Baud rate at which to communicate with target device]:BAUD: ' \
'--baud=[Baud rate at which to communicate with target device]:BAUD: ' \
'-p+[Serial port connected to target device]:PORT: ' \
'--port=[Serial port connected to target device]:PORT: ' \
'-f+[Flash frequency]:FREQ:((12mhz\:"12 MHz"
15mhz\:"15 MHz"
16mhz\:"16 MHz"
20mhz\:"20 MHz"
24mhz\:"24 MHz"
26mhz\:"26 MHz"
30mhz\:"30 MHz"
40mhz\:"40 MHz"
48mhz\:"48 MHz"
60mhz\:"60 MHz"
80mhz\:"80 MHz"))' \
'--flash-freq=[Flash frequency]:FREQ:((12mhz\:"12 MHz"
15mhz\:"15 MHz"
16mhz\:"16 MHz"
20mhz\:"20 MHz"
24mhz\:"24 MHz"
26mhz\:"26 MHz"
30mhz\:"30 MHz"
40mhz\:"40 MHz"
48mhz\:"48 MHz"
60mhz\:"60 MHz"
80mhz\:"80 MHz"))' \
'-m+[Flash mode to use]:MODE:((qio\:"Quad I/O (4 pins used for address & data)"
qout\:"Quad Output (4 pins used for data)"
dio\:"Dual I/O (2 pins used for address & data)"
dout\:"Dual Output (2 pins used for data)"))' \
'--flash-mode=[Flash mode to use]:MODE:((qio\:"Quad I/O (4 pins used for address & data)"
qout\:"Quad Output (4 pins used for data)"
dio\:"Dual I/O (2 pins used for address & data)"
dout\:"Dual Output (2 pins used for data)"))' \
'-s+[Flash size of the target]:SIZE:((256kb\:"256 KB"
512kb\:"512 KB"
1mb\:"1 MB"
2mb\:"2 MB"
4mb\:"4 MB"
8mb\:"8 MB"
16mb\:"16 MB"
32mb\:"32 MB"
64mb\:"64 MB"
128mb\:"128 MB"
256mb\:"256 MB"))' \
'--flash-size=[Flash size of the target]:SIZE:((256kb\:"256 KB"
512kb\:"512 KB"
1mb\:"1 MB"
2mb\:"2 MB"
4mb\:"4 MB"
8mb\:"8 MB"
16mb\:"16 MB"
32mb\:"32 MB"
64mb\:"64 MB"
128mb\:"128 MB"
256mb\:"256 MB"))' \
'--bootloader=[Path to a binary (.bin) bootloader file]:FILE:_files' \
'*--erase-parts=[Erase partitions by label]:LABELS: ' \
'*--erase-data-parts=[Erase specified data partitions]:PARTS: ' \
'--format=[Image format to flash]:FORMAT:((esp-bootloader\:"Use the second-stage bootloader from ESP-IDF"
direct-boot\:"Use direct boot and do not use a second-stage bootloader at all"))' \
'--monitor-baud=[Baud rate at which to read console output]:BAUD: ' \
'--partition-table=[Path to a CSV file containing partition table]:FILE:_files' \
'--no-stub[Do not use the RAM stub for loading]' \
'-M[Open a serial monitor after flashing]' \
'--monitor[Open a serial monitor after flashing]' \
'--ram[Load the application to RAM instead of Flash]' \
'-h[Print help (see more with '\''--help'\'')]' \
'--help[Print help (see more with '\''--help'\'')]' \
'-V[Print version]' \
'--version[Print version]' \
':image -- ELF image to flash:_files' \
&& ret=0
;;
(monitor)
_arguments "${_arguments_options[@]}" \
'-e+[Optional file name of the ELF image to load the symbols from]:FILE:_files' \
'--elf=[Optional file name of the ELF image to load the symbols from]:FILE:_files' \
'-b+[Baud rate at which to communicate with target device]:BAUD: ' \
'--baud=[Baud rate at which to communicate with target device]:BAUD: ' \
'-p+[Serial port connected to target device]:PORT: ' \
'--port=[Serial port connected to target device]:PORT: ' \
'--no-stub[Do not use the RAM stub for loading]' \
'-h[Print help]' \
'--help[Print help]' \
'-V[Print version]' \
'--version[Print version]' \
&& ret=0
;;
(partition-table)
_arguments "${_arguments_options[@]}" \
'-o+[Optional output file name, if unset will output to stdout]:FILE:_files' \
'--output=[Optional output file name, if unset will output to stdout]:FILE:_files' \
'(--to-csv)--to-binary[Convert CSV partition table to binary representation]' \
'(--to-binary)--to-csv[Convert binary partition table to CSV representation]' \
'-h[Print help (see more with '\''--help'\'')]' \
'--help[Print help (see more with '\''--help'\'')]' \
'-V[Print version]' \
'--version[Print version]' \
':partition_table -- Input partition table:_files' \
&& ret=0
;;
(save-image)
_arguments "${_arguments_options[@]}" \
'--format=[Image format to flash]:FORMAT:((esp-bootloader\:"Use the second-stage bootloader from ESP-IDF"
direct-boot\:"Use direct boot and do not use a second-stage bootloader at all"))' \
'-f+[Flash frequency]:FREQ:((12mhz\:"12 MHz"
15mhz\:"15 MHz"
16mhz\:"16 MHz"
20mhz\:"20 MHz"
24mhz\:"24 MHz"
26mhz\:"26 MHz"
30mhz\:"30 MHz"
40mhz\:"40 MHz"
48mhz\:"48 MHz"
60mhz\:"60 MHz"
80mhz\:"80 MHz"))' \
'--flash-freq=[Flash frequency]:FREQ:((12mhz\:"12 MHz"
15mhz\:"15 MHz"
16mhz\:"16 MHz"
20mhz\:"20 MHz"
24mhz\:"24 MHz"
26mhz\:"26 MHz"
30mhz\:"30 MHz"
40mhz\:"40 MHz"
48mhz\:"48 MHz"
60mhz\:"60 MHz"
80mhz\:"80 MHz"))' \
'-m+[Flash mode to use]:MODE:((qio\:"Quad I/O (4 pins used for address & data)"
qout\:"Quad Output (4 pins used for data)"
dio\:"Dual I/O (2 pins used for address & data)"
dout\:"Dual Output (2 pins used for data)"))' \
'--flash-mode=[Flash mode to use]:MODE:((qio\:"Quad I/O (4 pins used for address & data)"
qout\:"Quad Output (4 pins used for data)"
dio\:"Dual I/O (2 pins used for address & data)"
dout\:"Dual Output (2 pins used for data)"))' \
'-s+[Flash size of the target]:SIZE:((256kb\:"256 KB"
512kb\:"512 KB"
1mb\:"1 MB"
2mb\:"2 MB"
4mb\:"4 MB"
8mb\:"8 MB"
16mb\:"16 MB"
32mb\:"32 MB"
64mb\:"64 MB"
128mb\:"128 MB"
256mb\:"256 MB"))' \
'--flash-size=[Flash size of the target]:SIZE:((256kb\:"256 KB"
512kb\:"512 KB"
1mb\:"1 MB"
2mb\:"2 MB"
4mb\:"4 MB"
8mb\:"8 MB"
16mb\:"16 MB"
32mb\:"32 MB"
64mb\:"64 MB"
128mb\:"128 MB"
256mb\:"256 MB"))' \
'--bootloader=[Custom bootloader for merging]:FILE:_files' \
'--chip=[Chip to create an image for]:CHIP:((esp32\:"ESP32"
esp32c2\:"ESP32-C2, ESP8684"
esp32c3\:"ESP32-C3, ESP8685"
esp32c6\:"ESP32-C6"
esp32s2\:"ESP32-S2"
esp32s3\:"ESP32-S3"
esp32h2\:"ESP32-H2"
esp8266\:"ESP8266"))' \
'-T+[Custom partition table for merging]:FILE:_files' \
'--partition-table=[Custom partition table for merging]:FILE:_files' \
'--merge[Boolean flag to merge binaries into single binary]' \
'-P[Don'\''t pad the image to the flash size]' \
'--skip-padding[Don'\''t pad the image to the flash size]' \
'-h[Print help (see more with '\''--help'\'')]' \
'--help[Print help (see more with '\''--help'\'')]' \
'-V[Print version]' \
'--version[Print version]' \
':image -- ELF image to flash:_files' \
':file -- File name to save the generated image to:_files' \
&& ret=0
;;
(write-bin)
_arguments "${_arguments_options[@]}" \
'-b+[Baud rate at which to communicate with target device]:BAUD: ' \
'--baud=[Baud rate at which to communicate with target device]:BAUD: ' \
'-p+[Serial port connected to target device]:PORT: ' \
'--port=[Serial port connected to target device]:PORT: ' \
'--no-stub[Do not use the RAM stub for loading]' \
'-h[Print help]' \
'--help[Print help]' \
'-V[Print version]' \
'--version[Print version]' \
':addr -- Address at which to write the binary file:' \
':bin_file -- File containing the binary data to write:' \
&& ret=0
;;
(help)
_arguments "${_arguments_options[@]}" \
":: :_espflash__help_commands" \
"*::: :->help" \
&& ret=0

    case $state in
    (help)
        words=($line[1] "${words[@]}")
        (( CURRENT += 1 ))
        curcontext="${curcontext%:*:*}:espflash-help-command-$line[1]:"
        case $line[1] in
            (board-info)
_arguments "${_arguments_options[@]}" \
&& ret=0
;;
(completions)
_arguments "${_arguments_options[@]}" \
&& ret=0
;;
(erase-flash)
_arguments "${_arguments_options[@]}" \
&& ret=0
;;
(erase-parts)
_arguments "${_arguments_options[@]}" \
&& ret=0
;;
(erase-region)
_arguments "${_arguments_options[@]}" \
&& ret=0
;;
(flash)
_arguments "${_arguments_options[@]}" \
&& ret=0
;;
(monitor)
_arguments "${_arguments_options[@]}" \
&& ret=0
;;
(partition-table)
_arguments "${_arguments_options[@]}" \
&& ret=0
;;
(save-image)
_arguments "${_arguments_options[@]}" \
&& ret=0
;;
(write-bin)
_arguments "${_arguments_options[@]}" \
&& ret=0
;;
(help)
_arguments "${_arguments_options[@]}" \
&& ret=0
;;
        esac
    ;;
esac
;;
        esac
    ;;
esac
}

(( $+functions[_espflash_commands] )) ||
_espflash_commands() {
    local commands; commands=(
'board-info:Print information about a connected target device' \
'completions:Generate completions for the given shell' \
'erase-flash:Erase Flash entirely' \
'erase-parts:Erase specified partitions' \
'erase-region:Erase specified region' \
'flash:Flash an application in ELF format to a connected target device' \
'monitor:Open the serial monitor without flashing the connected target device' \
'partition-table:Convert partition tables between CSV and binary format' \
'save-image:Generate a binary application image and save it to a local disk' \
'write-bin:Write a binary file to a specific address in a target device'\''s flash' \
'help:Print this message or the help of the given subcommand(s)' \
    )
    _describe -t commands 'espflash commands' commands "$@"
}
(( $+functions[_espflash__board-info_commands] )) ||
_espflash__board-info_commands() {
    local commands; commands=()
    _describe -t commands 'espflash board-info commands' commands "$@"
}
(( $+functions[_espflash__help__board-info_commands] )) ||
_espflash__help__board-info_commands() {
    local commands; commands=()
    _describe -t commands 'espflash help board-info commands' commands "$@"
}
(( $+functions[_espflash__completions_commands] )) ||
_espflash__completions_commands() {
    local commands; commands=()
    _describe -t commands 'espflash completions commands' commands "$@"
}
(( $+functions[_espflash__help__completions_commands] )) ||
_espflash__help__completions_commands() {
    local commands; commands=()
    _describe -t commands 'espflash help completions commands' commands "$@"
}
(( $+functions[_espflash__erase-flash_commands] )) ||
_espflash__erase-flash_commands() {
    local commands; commands=()
    _describe -t commands 'espflash erase-flash commands' commands "$@"
}
(( $+functions[_espflash__help__erase-flash_commands] )) ||
_espflash__help__erase-flash_commands() {
    local commands; commands=()
    _describe -t commands 'espflash help erase-flash commands' commands "$@"
}
(( $+functions[_espflash__erase-parts_commands] )) ||
_espflash__erase-parts_commands() {
    local commands; commands=()
    _describe -t commands 'espflash erase-parts commands' commands "$@"
}
(( $+functions[_espflash__help__erase-parts_commands] )) ||
_espflash__help__erase-parts_commands() {
    local commands; commands=()
    _describe -t commands 'espflash help erase-parts commands' commands "$@"
}
(( $+functions[_espflash__erase-region_commands] )) ||
_espflash__erase-region_commands() {
    local commands; commands=()
    _describe -t commands 'espflash erase-region commands' commands "$@"
}
(( $+functions[_espflash__help__erase-region_commands] )) ||
_espflash__help__erase-region_commands() {
    local commands; commands=()
    _describe -t commands 'espflash help erase-region commands' commands "$@"
}
(( $+functions[_espflash__flash_commands] )) ||
_espflash__flash_commands() {
    local commands; commands=()
    _describe -t commands 'espflash flash commands' commands "$@"
}
(( $+functions[_espflash__help__flash_commands] )) ||
_espflash__help__flash_commands() {
    local commands; commands=()
    _describe -t commands 'espflash help flash commands' commands "$@"
}
(( $+functions[_espflash__help_commands] )) ||
_espflash__help_commands() {
    local commands; commands=(
'board-info:Print information about a connected target device' \
'completions:Generate completions for the given shell' \
'erase-flash:Erase Flash entirely' \
'erase-parts:Erase specified partitions' \
'erase-region:Erase specified region' \
'flash:Flash an application in ELF format to a connected target device' \
'monitor:Open the serial monitor without flashing the connected target device' \
'partition-table:Convert partition tables between CSV and binary format' \
'save-image:Generate a binary application image and save it to a local disk' \
'write-bin:Write a binary file to a specific address in a target device'\''s flash' \
'help:Print this message or the help of the given subcommand(s)' \
    )
    _describe -t commands 'espflash help commands' commands "$@"
}
(( $+functions[_espflash__help__help_commands] )) ||
_espflash__help__help_commands() {
    local commands; commands=()
    _describe -t commands 'espflash help help commands' commands "$@"
}
(( $+functions[_espflash__help__monitor_commands] )) ||
_espflash__help__monitor_commands() {
    local commands; commands=()
    _describe -t commands 'espflash help monitor commands' commands "$@"
}
(( $+functions[_espflash__monitor_commands] )) ||
_espflash__monitor_commands() {
    local commands; commands=()
    _describe -t commands 'espflash monitor commands' commands "$@"
}
(( $+functions[_espflash__help__partition-table_commands] )) ||
_espflash__help__partition-table_commands() {
    local commands; commands=()
    _describe -t commands 'espflash help partition-table commands' commands "$@"
}
(( $+functions[_espflash__partition-table_commands] )) ||
_espflash__partition-table_commands() {
    local commands; commands=()
    _describe -t commands 'espflash partition-table commands' commands "$@"
}
(( $+functions[_espflash__help__save-image_commands] )) ||
_espflash__help__save-image_commands() {
    local commands; commands=()
    _describe -t commands 'espflash help save-image commands' commands "$@"
}
(( $+functions[_espflash__save-image_commands] )) ||
_espflash__save-image_commands() {
    local commands; commands=()
    _describe -t commands 'espflash save-image commands' commands "$@"
}
(( $+functions[_espflash__help__write-bin_commands] )) ||
_espflash__help__write-bin_commands() {
    local commands; commands=()
    _describe -t commands 'espflash help write-bin commands' commands "$@"
}
(( $+functions[_espflash__write-bin_commands] )) ||
_espflash__write-bin_commands() {
    local commands; commands=()
    _describe -t commands 'espflash write-bin commands' commands "$@"
}

if [ "$funcstack[1]" = "_espflash" ]; then
    _espflash "$@"
else
    compdef _espflash espflash
fi
