#compdef asak

autoload -U is-at-least

_asak() {
    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]' \
":: :_asak_commands" \
"*::: :->asak" \
&& ret=0
    case $state in
    (asak)
        words=($line[1] "${words[@]}")
        (( CURRENT += 1 ))
        curcontext="${curcontext%:*:*}:asak-command-$line[1]:"
        case $line[1] in
            (rec)
_arguments "${_arguments_options[@]}" : \
'-d+[The audio device index to use]:DEVICE: ' \
'--device=[The audio device index to use]:DEVICE: ' \
'-h[Print help]' \
'--help[Print help]' \
'::output -- Path for the output audio file, e.g. `output`:' \
&& ret=0
;;
(play)
_arguments "${_arguments_options[@]}" : \
'-d+[The audio device index to use]:DEVICE: ' \
'--device=[The audio device index to use]:DEVICE: ' \
'-h[Print help]' \
'--help[Print help]' \
'::input -- Path to the audio file to play, e.g. `input.wav`, `input.ogg`, or `input.mp3`:' \
&& ret=0
;;
(monitor)
_arguments "${_arguments_options[@]}" : \
'-b+[Buffer size for the audio input monitoring, defaults to 1024, the higher the value the more latency]:BUFFER_SIZE: ' \
'--buffer-size=[Buffer size for the audio input monitoring, defaults to 1024, the higher the value the more latency]:BUFFER_SIZE: ' \
'-h[Print help]' \
'--help[Print help]' \
&& ret=0
;;
(list)
_arguments "${_arguments_options[@]}" : \
'-h[Print help]' \
'--help[Print help]' \
&& ret=0
;;
(help)
_arguments "${_arguments_options[@]}" : \
":: :_asak__help_commands" \
"*::: :->help" \
&& ret=0

    case $state in
    (help)
        words=($line[1] "${words[@]}")
        (( CURRENT += 1 ))
        curcontext="${curcontext%:*:*}:asak-help-command-$line[1]:"
        case $line[1] in
            (rec)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(play)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(monitor)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(list)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(help)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
        esac
    ;;
esac
;;
        esac
    ;;
esac
}

(( $+functions[_asak_commands] )) ||
_asak_commands() {
    local commands; commands=(
'rec:Record an audio file' \
'play:Play an audio file' \
'monitor:Monitor audio input with scopes' \
'list:List available audio devices' \
'help:Print this message or the help of the given subcommand(s)' \
    )
    _describe -t commands 'asak commands' commands "$@"
}
(( $+functions[_asak__help_commands] )) ||
_asak__help_commands() {
    local commands; commands=(
'rec:Record an audio file' \
'play:Play an audio file' \
'monitor:Monitor audio input with scopes' \
'list:List available audio devices' \
'help:Print this message or the help of the given subcommand(s)' \
    )
    _describe -t commands 'asak help commands' commands "$@"
}
(( $+functions[_asak__help__help_commands] )) ||
_asak__help__help_commands() {
    local commands; commands=()
    _describe -t commands 'asak help help commands' commands "$@"
}
(( $+functions[_asak__help__list_commands] )) ||
_asak__help__list_commands() {
    local commands; commands=()
    _describe -t commands 'asak help list commands' commands "$@"
}
(( $+functions[_asak__help__monitor_commands] )) ||
_asak__help__monitor_commands() {
    local commands; commands=()
    _describe -t commands 'asak help monitor commands' commands "$@"
}
(( $+functions[_asak__help__play_commands] )) ||
_asak__help__play_commands() {
    local commands; commands=()
    _describe -t commands 'asak help play commands' commands "$@"
}
(( $+functions[_asak__help__rec_commands] )) ||
_asak__help__rec_commands() {
    local commands; commands=()
    _describe -t commands 'asak help rec commands' commands "$@"
}
(( $+functions[_asak__list_commands] )) ||
_asak__list_commands() {
    local commands; commands=()
    _describe -t commands 'asak list commands' commands "$@"
}
(( $+functions[_asak__monitor_commands] )) ||
_asak__monitor_commands() {
    local commands; commands=()
    _describe -t commands 'asak monitor commands' commands "$@"
}
(( $+functions[_asak__play_commands] )) ||
_asak__play_commands() {
    local commands; commands=()
    _describe -t commands 'asak play commands' commands "$@"
}
(( $+functions[_asak__rec_commands] )) ||
_asak__rec_commands() {
    local commands; commands=()
    _describe -t commands 'asak rec commands' commands "$@"
}

if [ "$funcstack[1]" = "_asak" ]; then
    _asak "$@"
else
    compdef _asak asak
fi
