#compdef keepawake

autoload -U is-at-least

_keepawake() {
    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[@]}" : \
'--completions=[Generate shell completions]:SHELL:(bash elvish fish powershell zsh)' \
'-w+[Wait for the process with the specified PID to exit. This option is ignored when used with the COMMAND argument]:PID:_default' \
'-d[Keep display on]' \
'--display[Keep display on]' \
'-i[Keep system from idle sleeping]' \
'--idle[Keep system from idle sleeping]' \
'-s[Keep system from explicitly sleeping (Functionality and conditions for this to work vary by OS)]' \
'--sleep[Keep system from explicitly sleeping (Functionality and conditions for this to work vary by OS)]' \
'-h[Print help]' \
'--help[Print help]' \
'-V[Print version]' \
'--version[Print version]' \
'*::command -- Run the command and wait for it to exit, keeping the computer awake while it runs:_cmdambivalent' \
&& ret=0
}

(( $+functions[_keepawake_commands] )) ||
_keepawake_commands() {
    local commands; commands=()
    _describe -t commands 'keepawake commands' commands "$@"
}

if [ "$funcstack[1]" = "_keepawake" ]; then
    _keepawake "$@"
else
    compdef _keepawake keepawake
fi
