#compdef panelctl

autoload -U is-at-least

_panelctl() {
    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[@]}" : \
'--panel=[多面板機種：要操作的面板編號（＝銘板編號；\`panelctl list\` 看全部）。單面板不用給]:PANEL:_default' \
'-h[Print help]' \
'--help[Print help]' \
'-V[Print version]' \
'--version[Print version]' \
":: :_panelctl_commands" \
"*::: :->panelctl" \
&& ret=0
    case $state in
    (panelctl)
        words=($line[1] "${words[@]}")
        (( CURRENT += 1 ))
        curcontext="${curcontext%:*:*}:panelctl-command-$line[1]:"
        case $line[1] in
            (list)
_arguments "${_arguments_options[@]}" : \
'--panel=[多面板機種：要操作的面板編號（＝銘板編號；\`panelctl list\` 看全部）。單面板不用給]:PANEL:_default' \
'-h[Print help]' \
'--help[Print help]' \
&& ret=0
;;
(identify)
_arguments "${_arguments_options[@]}" : \
'--panel=[多面板機種：要操作的面板編號（＝銘板編號；\`panelctl list\` 看全部）。單面板不用給]:PANEL:_default' \
'-h[Print help]' \
'--help[Print help]' \
'*::panels:_default' \
&& ret=0
;;
(swap)
_arguments "${_arguments_options[@]}" : \
'--wiring=[接線定義檔]:WIRING:_files' \
'--panel=[多面板機種：要操作的面板編號（＝銘板編號；\`panelctl list\` 看全部）。單面板不用給]:PANEL:_default' \
'-h[Print help]' \
'--help[Print help]' \
':a:_default' \
':b:_default' \
&& ret=0
;;
(status)
_arguments "${_arguments_options[@]}" : \
'--panel=[多面板機種：要操作的面板編號（＝銘板編號；\`panelctl list\` 看全部）。單面板不用給]:PANEL:_default' \
'--json[]' \
'-h[Print help]' \
'--help[Print help]' \
&& ret=0
;;
(doctor)
_arguments "${_arguments_options[@]}" : \
'--config=[設定檔路徑]:CONFIG:_files' \
'--panel=[多面板機種：要操作的面板編號（＝銘板編號；\`panelctl list\` 看全部）。單面板不用給]:PANEL:_default' \
'-h[Print help]' \
'--help[Print help]' \
&& ret=0
;;
(refresh)
_arguments "${_arguments_options[@]}" : \
'--mode=[m1～m4、m9]:MODE:_default' \
'--priority=[]:PRIORITY:(normal menu shutdown)' \
'--rest=[做完之後面板放哪裡；不給則交給服務（預設斷電，有人持有保持通電時待命）]:REST:(keep sleep off)' \
'--combo=[刷完接 M9（只有 TCON2；**只對 M9 是放電的韌體用，目前只有 V10059**）： \`--combo\` 或 \`--combo now\` 立刻接；\`--combo defer\` 記帳，由服務找空檔補]::COMBO:(now defer)' \
'--panel=[多面板機種：要操作的面板編號（＝銘板編號；\`panelctl list\` 看全部）。單面板不用給]:PANEL:_default' \
'--no-wait[送出後不等結果，印出請求編號就結束（之後用 \`panelctl result\`）]' \
'-h[Print help]' \
'--help[Print help]' \
':image:_files' \
&& ret=0
;;
(partial)
_arguments "${_arguments_options[@]}" : \
'--x=[]:X:_default' \
'--y=[]:Y:_default' \
'--w=[]:W:_default' \
'--h=[]:H:_default' \
'--mode=[]:MODE:_default' \
'--priority=[]:PRIORITY:(normal menu shutdown)' \
'--rest=[]:REST:(keep sleep off)' \
'--combo=[刷完接 M9（只有 TCON2；**只對 M9 是放電的韌體用，目前只有 V10059**）： \`--combo\` 或 \`--combo now\` 立刻接；\`--combo defer\` 記帳，由服務找空檔補]::COMBO:(now defer)' \
'--panel=[多面板機種：要操作的面板編號（＝銘板編號；\`panelctl list\` 看全部）。單面板不用給]:PANEL:_default' \
'-h[Print help]' \
'--help[Print help]' \
':image:_files' \
&& ret=0
;;
(hold)
_arguments "${_arguments_options[@]}" : \
'--seconds=[最長幾秒（0＝預設 300，上限 3600）]:SECONDS:_default' \
'--panel=[多面板機種：要操作的面板編號（＝銘板編號；\`panelctl list\` 看全部）。單面板不用給]:PANEL:_default' \
'-h[Print help]' \
'--help[Print help]' \
&& ret=0
;;
(white)
_arguments "${_arguments_options[@]}" : \
'--panel=[多面板機種：要操作的面板編號（＝銘板編號；\`panelctl list\` 看全部）。單面板不用給]:PANEL:_default' \
'-h[Print help]' \
'--help[Print help]' \
&& ret=0
;;
(discharge)
_arguments "${_arguments_options[@]}" : \
'--panel=[多面板機種：要操作的面板編號（＝銘板編號；\`panelctl list\` 看全部）。單面板不用給]:PANEL:_default' \
'-h[Print help]' \
'--help[Print help]' \
&& ret=0
;;
(reset)
_arguments "${_arguments_options[@]}" : \
'--priority=[]:PRIORITY:(normal menu shutdown)' \
'--rest=[]:REST:(keep sleep off)' \
'--panel=[多面板機種：要操作的面板編號（＝銘板編號；\`panelctl list\` 看全部）。單面板不用給]:PANEL:_default' \
'-h[Print help]' \
'--help[Print help]' \
&& ret=0
;;
(flash)
_arguments "${_arguments_options[@]}" : \
'--panel=[多面板機種：要操作的面板編號（＝銘板編號；\`panelctl list\` 看全部）。單面板不用給]:PANEL:_default' \
'-h[Print help]' \
'--help[Print help]' \
':firmware:_files' \
&& ret=0
;;
(power-off)
_arguments "${_arguments_options[@]}" : \
'--panel=[多面板機種：要操作的面板編號（＝銘板編號；\`panelctl list\` 看全部）。單面板不用給]:PANEL:_default' \
'-h[Print help]' \
'--help[Print help]' \
&& ret=0
;;
(firmware)
_arguments "${_arguments_options[@]}" : \
'--panel=[多面板機種：要操作的面板編號（＝銘板編號；\`panelctl list\` 看全部）。單面板不用給]:PANEL:_default' \
'--json[]' \
'-h[Print help]' \
'--help[Print help]' \
&& ret=0
;;
(ints)
_arguments "${_arguments_options[@]}" : \
'--panel=[多面板機種：要操作的面板編號（＝銘板編號；\`panelctl list\` 看全部）。單面板不用給]:PANEL:_default' \
'-h[Print help]' \
'--help[Print help]' \
&& ret=0
;;
(result)
_arguments "${_arguments_options[@]}" : \
'--panel=[多面板機種：要操作的面板編號（＝銘板編號；\`panelctl list\` 看全部）。單面板不用給]:PANEL:_default' \
'-h[Print help]' \
'--help[Print help]' \
':id:_default' \
&& ret=0
;;
(completions)
_arguments "${_arguments_options[@]}" : \
'--panel=[多面板機種：要操作的面板編號（＝銘板編號；\`panelctl list\` 看全部）。單面板不用給]:PANEL:_default' \
'-h[Print help]' \
'--help[Print help]' \
':shell:(bash elvish fish powershell zsh)' \
&& ret=0
;;
(pack)
_arguments "${_arguments_options[@]}" : \
'--tcon=[面板世代；不給則問服務]:TCON:(tcon1 tcon2)' \
'--panel=[多面板機種：要操作的面板編號（＝銘板編號；\`panelctl list\` 看全部）。單面板不用給]:PANEL:_default' \
'-h[Print help]' \
'--help[Print help]' \
':bmp:_files' \
':out:_files' \
&& ret=0
;;
(help)
_arguments "${_arguments_options[@]}" : \
":: :_panelctl__subcmd__help_commands" \
"*::: :->help" \
&& ret=0

    case $state in
    (help)
        words=($line[1] "${words[@]}")
        (( CURRENT += 1 ))
        curcontext="${curcontext%:*:*}:panelctl-help-command-$line[1]:"
        case $line[1] in
            (list)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(identify)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(swap)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(status)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(doctor)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(refresh)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(partial)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(hold)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(white)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(discharge)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(reset)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(flash)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(power-off)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(firmware)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(ints)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(result)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(completions)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(pack)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(help)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
        esac
    ;;
esac
;;
        esac
    ;;
esac
}

(( $+functions[_panelctl_commands] )) ||
_panelctl_commands() {
    local commands; commands=(
'list:多面板：列出所有面板（編號、USB 路徑、接口、是否接著、bin code）' \
'identify:識別：刷出大字編號，對照背後的銘板（REQ-N05）。多面板給編號（例如 1 3 5）或 all；不給就是 --panel 那片' \
'swap:多面板：兩片插反時，在接線定義裡對調它們的編號（REQ-N03），之後要重啟服務' \
'status:服務與面板的目前狀態（預設）' \
'doctor:一頁結論與處置建議；服務沒在跑也能用（只做不碰面板的檢查）' \
'refresh:整頁刷新。圖檔是 .pmraw，或 24 位元 BMP（會自動轉換）' \
'partial:局部刷新；區域必須是滿版長邊或短邊的條狀區域。圖檔大小就是區域大小' \
'hold:要求面板保持通電，直到按 Ctrl-C、期限到或這個程式結束（用來測試與維修）' \
'white:全白刷新（關機前用）' \
'discharge:放電：只做 M9、不送影像，還清 \`--combo defer\` 欠的 M9；沒欠就什麼都不做（只對 V10059 這類韌體）' \
'reset:顯示重置（M0），關機前清畫面用' \
'flash:更新 TCON 韌體（擦除再逐頁燒錄，需數十秒到數分鐘）' \
'power-off:讓面板去休息：斷電並歸還 10A 租約（系統要休眠前用）；等斷電完成才回來' \
'firmware:讀面板韌體版本' \
'ints:讀面板開機後的 INTS 暫存器並解讀' \
'result:查詢已完成請求的結果' \
'completions:輸出 shell 的 tab 補齊腳本（bash、zsh、fish 等）' \
'pack:把 24 位元 BMP 轉成 .pmraw（面板原生快取格式）' \
'help:Print this message or the help of the given subcommand(s)' \
    )
    _describe -t commands 'panelctl commands' commands "$@"
}
(( $+functions[_panelctl__subcmd__completions_commands] )) ||
_panelctl__subcmd__completions_commands() {
    local commands; commands=()
    _describe -t commands 'panelctl completions commands' commands "$@"
}
(( $+functions[_panelctl__subcmd__discharge_commands] )) ||
_panelctl__subcmd__discharge_commands() {
    local commands; commands=()
    _describe -t commands 'panelctl discharge commands' commands "$@"
}
(( $+functions[_panelctl__subcmd__doctor_commands] )) ||
_panelctl__subcmd__doctor_commands() {
    local commands; commands=()
    _describe -t commands 'panelctl doctor commands' commands "$@"
}
(( $+functions[_panelctl__subcmd__firmware_commands] )) ||
_panelctl__subcmd__firmware_commands() {
    local commands; commands=()
    _describe -t commands 'panelctl firmware commands' commands "$@"
}
(( $+functions[_panelctl__subcmd__flash_commands] )) ||
_panelctl__subcmd__flash_commands() {
    local commands; commands=()
    _describe -t commands 'panelctl flash commands' commands "$@"
}
(( $+functions[_panelctl__subcmd__help_commands] )) ||
_panelctl__subcmd__help_commands() {
    local commands; commands=(
'list:多面板：列出所有面板（編號、USB 路徑、接口、是否接著、bin code）' \
'identify:識別：刷出大字編號，對照背後的銘板（REQ-N05）。多面板給編號（例如 1 3 5）或 all；不給就是 --panel 那片' \
'swap:多面板：兩片插反時，在接線定義裡對調它們的編號（REQ-N03），之後要重啟服務' \
'status:服務與面板的目前狀態（預設）' \
'doctor:一頁結論與處置建議；服務沒在跑也能用（只做不碰面板的檢查）' \
'refresh:整頁刷新。圖檔是 .pmraw，或 24 位元 BMP（會自動轉換）' \
'partial:局部刷新；區域必須是滿版長邊或短邊的條狀區域。圖檔大小就是區域大小' \
'hold:要求面板保持通電，直到按 Ctrl-C、期限到或這個程式結束（用來測試與維修）' \
'white:全白刷新（關機前用）' \
'discharge:放電：只做 M9、不送影像，還清 \`--combo defer\` 欠的 M9；沒欠就什麼都不做（只對 V10059 這類韌體）' \
'reset:顯示重置（M0），關機前清畫面用' \
'flash:更新 TCON 韌體（擦除再逐頁燒錄，需數十秒到數分鐘）' \
'power-off:讓面板去休息：斷電並歸還 10A 租約（系統要休眠前用）；等斷電完成才回來' \
'firmware:讀面板韌體版本' \
'ints:讀面板開機後的 INTS 暫存器並解讀' \
'result:查詢已完成請求的結果' \
'completions:輸出 shell 的 tab 補齊腳本（bash、zsh、fish 等）' \
'pack:把 24 位元 BMP 轉成 .pmraw（面板原生快取格式）' \
'help:Print this message or the help of the given subcommand(s)' \
    )
    _describe -t commands 'panelctl help commands' commands "$@"
}
(( $+functions[_panelctl__subcmd__help__subcmd__completions_commands] )) ||
_panelctl__subcmd__help__subcmd__completions_commands() {
    local commands; commands=()
    _describe -t commands 'panelctl help completions commands' commands "$@"
}
(( $+functions[_panelctl__subcmd__help__subcmd__discharge_commands] )) ||
_panelctl__subcmd__help__subcmd__discharge_commands() {
    local commands; commands=()
    _describe -t commands 'panelctl help discharge commands' commands "$@"
}
(( $+functions[_panelctl__subcmd__help__subcmd__doctor_commands] )) ||
_panelctl__subcmd__help__subcmd__doctor_commands() {
    local commands; commands=()
    _describe -t commands 'panelctl help doctor commands' commands "$@"
}
(( $+functions[_panelctl__subcmd__help__subcmd__firmware_commands] )) ||
_panelctl__subcmd__help__subcmd__firmware_commands() {
    local commands; commands=()
    _describe -t commands 'panelctl help firmware commands' commands "$@"
}
(( $+functions[_panelctl__subcmd__help__subcmd__flash_commands] )) ||
_panelctl__subcmd__help__subcmd__flash_commands() {
    local commands; commands=()
    _describe -t commands 'panelctl help flash commands' commands "$@"
}
(( $+functions[_panelctl__subcmd__help__subcmd__help_commands] )) ||
_panelctl__subcmd__help__subcmd__help_commands() {
    local commands; commands=()
    _describe -t commands 'panelctl help help commands' commands "$@"
}
(( $+functions[_panelctl__subcmd__help__subcmd__hold_commands] )) ||
_panelctl__subcmd__help__subcmd__hold_commands() {
    local commands; commands=()
    _describe -t commands 'panelctl help hold commands' commands "$@"
}
(( $+functions[_panelctl__subcmd__help__subcmd__identify_commands] )) ||
_panelctl__subcmd__help__subcmd__identify_commands() {
    local commands; commands=()
    _describe -t commands 'panelctl help identify commands' commands "$@"
}
(( $+functions[_panelctl__subcmd__help__subcmd__ints_commands] )) ||
_panelctl__subcmd__help__subcmd__ints_commands() {
    local commands; commands=()
    _describe -t commands 'panelctl help ints commands' commands "$@"
}
(( $+functions[_panelctl__subcmd__help__subcmd__list_commands] )) ||
_panelctl__subcmd__help__subcmd__list_commands() {
    local commands; commands=()
    _describe -t commands 'panelctl help list commands' commands "$@"
}
(( $+functions[_panelctl__subcmd__help__subcmd__pack_commands] )) ||
_panelctl__subcmd__help__subcmd__pack_commands() {
    local commands; commands=()
    _describe -t commands 'panelctl help pack commands' commands "$@"
}
(( $+functions[_panelctl__subcmd__help__subcmd__partial_commands] )) ||
_panelctl__subcmd__help__subcmd__partial_commands() {
    local commands; commands=()
    _describe -t commands 'panelctl help partial commands' commands "$@"
}
(( $+functions[_panelctl__subcmd__help__subcmd__power-off_commands] )) ||
_panelctl__subcmd__help__subcmd__power-off_commands() {
    local commands; commands=()
    _describe -t commands 'panelctl help power-off commands' commands "$@"
}
(( $+functions[_panelctl__subcmd__help__subcmd__refresh_commands] )) ||
_panelctl__subcmd__help__subcmd__refresh_commands() {
    local commands; commands=()
    _describe -t commands 'panelctl help refresh commands' commands "$@"
}
(( $+functions[_panelctl__subcmd__help__subcmd__reset_commands] )) ||
_panelctl__subcmd__help__subcmd__reset_commands() {
    local commands; commands=()
    _describe -t commands 'panelctl help reset commands' commands "$@"
}
(( $+functions[_panelctl__subcmd__help__subcmd__result_commands] )) ||
_panelctl__subcmd__help__subcmd__result_commands() {
    local commands; commands=()
    _describe -t commands 'panelctl help result commands' commands "$@"
}
(( $+functions[_panelctl__subcmd__help__subcmd__status_commands] )) ||
_panelctl__subcmd__help__subcmd__status_commands() {
    local commands; commands=()
    _describe -t commands 'panelctl help status commands' commands "$@"
}
(( $+functions[_panelctl__subcmd__help__subcmd__swap_commands] )) ||
_panelctl__subcmd__help__subcmd__swap_commands() {
    local commands; commands=()
    _describe -t commands 'panelctl help swap commands' commands "$@"
}
(( $+functions[_panelctl__subcmd__help__subcmd__white_commands] )) ||
_panelctl__subcmd__help__subcmd__white_commands() {
    local commands; commands=()
    _describe -t commands 'panelctl help white commands' commands "$@"
}
(( $+functions[_panelctl__subcmd__hold_commands] )) ||
_panelctl__subcmd__hold_commands() {
    local commands; commands=()
    _describe -t commands 'panelctl hold commands' commands "$@"
}
(( $+functions[_panelctl__subcmd__identify_commands] )) ||
_panelctl__subcmd__identify_commands() {
    local commands; commands=()
    _describe -t commands 'panelctl identify commands' commands "$@"
}
(( $+functions[_panelctl__subcmd__ints_commands] )) ||
_panelctl__subcmd__ints_commands() {
    local commands; commands=()
    _describe -t commands 'panelctl ints commands' commands "$@"
}
(( $+functions[_panelctl__subcmd__list_commands] )) ||
_panelctl__subcmd__list_commands() {
    local commands; commands=()
    _describe -t commands 'panelctl list commands' commands "$@"
}
(( $+functions[_panelctl__subcmd__pack_commands] )) ||
_panelctl__subcmd__pack_commands() {
    local commands; commands=()
    _describe -t commands 'panelctl pack commands' commands "$@"
}
(( $+functions[_panelctl__subcmd__partial_commands] )) ||
_panelctl__subcmd__partial_commands() {
    local commands; commands=()
    _describe -t commands 'panelctl partial commands' commands "$@"
}
(( $+functions[_panelctl__subcmd__power-off_commands] )) ||
_panelctl__subcmd__power-off_commands() {
    local commands; commands=()
    _describe -t commands 'panelctl power-off commands' commands "$@"
}
(( $+functions[_panelctl__subcmd__refresh_commands] )) ||
_panelctl__subcmd__refresh_commands() {
    local commands; commands=()
    _describe -t commands 'panelctl refresh commands' commands "$@"
}
(( $+functions[_panelctl__subcmd__reset_commands] )) ||
_panelctl__subcmd__reset_commands() {
    local commands; commands=()
    _describe -t commands 'panelctl reset commands' commands "$@"
}
(( $+functions[_panelctl__subcmd__result_commands] )) ||
_panelctl__subcmd__result_commands() {
    local commands; commands=()
    _describe -t commands 'panelctl result commands' commands "$@"
}
(( $+functions[_panelctl__subcmd__status_commands] )) ||
_panelctl__subcmd__status_commands() {
    local commands; commands=()
    _describe -t commands 'panelctl status commands' commands "$@"
}
(( $+functions[_panelctl__subcmd__swap_commands] )) ||
_panelctl__subcmd__swap_commands() {
    local commands; commands=()
    _describe -t commands 'panelctl swap commands' commands "$@"
}
(( $+functions[_panelctl__subcmd__white_commands] )) ||
_panelctl__subcmd__white_commands() {
    local commands; commands=()
    _describe -t commands 'panelctl white commands' commands "$@"
}

if [ "$funcstack[1]" = "_panelctl" ]; then
    _panelctl "$@"
else
    compdef _panelctl panelctl
fi
