#compdef asciinema

autoload -U is-at-least

_asciinema() {
    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[@]}" : \
'--server-url=[asciinema server URL]:URL:_default' \
'-q[Quiet mode, i.e. suppress diagnostic messages]' \
'--quiet[Quiet mode, i.e. suppress diagnostic messages]' \
'-h[Print help]' \
'--help[Print help]' \
'-V[Print version]' \
'--version[Print version]' \
":: :_asciinema_commands" \
"*::: :->asciinema" \
&& ret=0
    case $state in
    (asciinema)
        words=($line[1] "${words[@]}")
        (( CURRENT += 1 ))
        curcontext="${curcontext%:*:*}:asciinema-command-$line[1]:"
        case $line[1] in
            (rec)
_arguments "${_arguments_options[@]}" : \
'-f+[Output file format \[default\: asciicast-v3\]]:FORMAT:(asciicast-v3 asciicast-v2 raw txt)' \
'--output-format=[Output file format \[default\: asciicast-v3\]]:FORMAT:(asciicast-v3 asciicast-v2 raw txt)' \
'-c+[Command to start in the session \[default\: \$SHELL\]]:COMMAND:_default' \
'--command=[Command to start in the session \[default\: \$SHELL\]]:COMMAND:_default' \
'--rec-env=[Comma-separated list of env vars to capture \[default\: SHELL\]]:VARS:_default' \
'-t+[Title of the recording]:TITLE:_default' \
'--title=[Title of the recording]:TITLE:_default' \
'-i+[Limit idle time to a given number of seconds]:SECS:_default' \
'--idle-time-limit=[Limit idle time to a given number of seconds]:SECS:_default' \
'--window-size=[Override terminal size for the session]:COLSxROWS:_default' \
'--cols=[]:COLS:_default' \
'--rows=[]:ROWS:_default' \
'--server-url=[asciinema server URL]:URL:_default' \
'-I[Enable input (keys) recording]' \
'--rec-input[Enable input (keys) recording]' \
'-a[Append to an existing recording file]' \
'--append[Append to an existing recording file]' \
'(-a --append)--overwrite[Overwrite output file if it already exists]' \
'--headless[Headless mode, i.e. don'\''t use TTY for input/output]' \
'--raw[]' \
'-q[Quiet mode, i.e. suppress diagnostic messages]' \
'--quiet[Quiet mode, i.e. suppress diagnostic messages]' \
'-h[Print help]' \
'--help[Print help]' \
':output_path -- Output file path:_default' \
&& ret=0
;;
(play)
_arguments "${_arguments_options[@]}" : \
'-i+[Limit idle time to a given number of seconds]:SECS:_default' \
'--idle-time-limit=[Limit idle time to a given number of seconds]:SECS:_default' \
'-s+[Set playback speed]:SPEED:_default' \
'--speed=[Set playback speed]:SPEED:_default' \
'--server-url=[asciinema server URL]:URL:_default' \
'-l[Loop loop loop loop]' \
'--loop[Loop loop loop loop]' \
'-m[Automatically pause on markers]' \
'--pause-on-markers[Automatically pause on markers]' \
'-r[Auto-resize terminal window to always match the original size (supported on some terminals)]' \
'--resize[Auto-resize terminal window to always match the original size (supported on some terminals)]' \
'-q[Quiet mode, i.e. suppress diagnostic messages]' \
'--quiet[Quiet mode, i.e. suppress diagnostic messages]' \
'-h[Print help]' \
'--help[Print help]' \
':filename:_default' \
&& ret=0
;;
(stream)
_arguments "${_arguments_options[@]}" : \
'-l+[Stream the session via a local HTTP server]' \
'--local=[Stream the session via a local HTTP server]' \
'-r+[Stream the session via a remote asciinema server]' \
'--remote=[Stream the session via a remote asciinema server]' \
'-c+[Command to start in the session \[default\: \$SHELL\]]:COMMAND:_default' \
'--command=[Command to start in the session \[default\: \$SHELL\]]:COMMAND:_default' \
'--rec-env=[Comma-separated list of env vars to capture \[default\: SHELL\]]:VARS:_default' \
'--window-size=[Override terminal size for the session]:COLSxROWS:_default' \
'--log-file=[Log file path]:PATH:_files' \
'--server-url=[asciinema server URL]:URL:_default' \
'-I[Enable input (keys) recording]' \
'--rec-input[Enable input (keys) recording]' \
'--headless[Headless mode, i.e. don'\''t use TTY for input/output]' \
'-q[Quiet mode, i.e. suppress diagnostic messages]' \
'--quiet[Quiet mode, i.e. suppress diagnostic messages]' \
'-h[Print help]' \
'--help[Print help]' \
&& ret=0
;;
(session)
_arguments "${_arguments_options[@]}" : \
'-o+[Save the session in a file]:PATH:_default' \
'--output-file=[Save the session in a file]:PATH:_default' \
'-f+[Output file format \[default\: asciicast-v3\]]:FORMAT:(asciicast-v3 asciicast-v2 raw txt)' \
'--output-format=[Output file format \[default\: asciicast-v3\]]:FORMAT:(asciicast-v3 asciicast-v2 raw txt)' \
'-l+[Stream the session via a local HTTP server]' \
'--stream-local=[Stream the session via a local HTTP server]' \
'-r+[Stream the session via a remote asciinema server]' \
'--stream-remote=[Stream the session via a remote asciinema server]' \
'-c+[Command to start in the session \[default\: \$SHELL\]]:COMMAND:_default' \
'--command=[Command to start in the session \[default\: \$SHELL\]]:COMMAND:_default' \
'--rec-env=[Comma-separated list of env vars to capture \[default\: SHELL\]]:VARS:_default' \
'-t+[Title of the recording]:TITLE:_default' \
'--title=[Title of the recording]:TITLE:_default' \
'-i+[Limit idle time to a given number of seconds]:SECS:_default' \
'--idle-time-limit=[Limit idle time to a given number of seconds]:SECS:_default' \
'--window-size=[Override terminal size for the session]:COLSxROWS:_default' \
'--log-file=[Log file path]:PATH:_files' \
'--server-url=[asciinema server URL]:URL:_default' \
'-I[Enable input (keys) recording]' \
'--rec-input[Enable input (keys) recording]' \
'-a[Append to an existing recording file]' \
'--append[Append to an existing recording file]' \
'(-a --append)--overwrite[Overwrite output file if it already exists]' \
'--headless[Headless mode, i.e. don'\''t use TTY for input/output]' \
'-q[Quiet mode, i.e. suppress diagnostic messages]' \
'--quiet[Quiet mode, i.e. suppress diagnostic messages]' \
'-h[Print help]' \
'--help[Print help]' \
&& ret=0
;;
(cat)
_arguments "${_arguments_options[@]}" : \
'--server-url=[asciinema server URL]:URL:_default' \
'-q[Quiet mode, i.e. suppress diagnostic messages]' \
'--quiet[Quiet mode, i.e. suppress diagnostic messages]' \
'-h[Print help]' \
'--help[Print help]' \
'*::filename:_default' \
&& ret=0
;;
(convert)
_arguments "${_arguments_options[@]}" : \
'-f+[Output file format \[default\: asciicast-v3\]]:FORMAT:(asciicast-v3 asciicast-v2 raw txt)' \
'--output-format=[Output file format \[default\: asciicast-v3\]]:FORMAT:(asciicast-v3 asciicast-v2 raw txt)' \
'--server-url=[asciinema server URL]:URL:_default' \
'--overwrite[Overwrite target file if it already exists]' \
'-q[Quiet mode, i.e. suppress diagnostic messages]' \
'--quiet[Quiet mode, i.e. suppress diagnostic messages]' \
'-h[Print help]' \
'--help[Print help]' \
':input_filename -- File to convert from, in asciicast format (use - for stdin):_default' \
':output_filename -- File to convert to (use - for stdout):_default' \
&& ret=0
;;
(upload)
_arguments "${_arguments_options[@]}" : \
'--server-url=[asciinema server URL]:URL:_default' \
'-q[Quiet mode, i.e. suppress diagnostic messages]' \
'--quiet[Quiet mode, i.e. suppress diagnostic messages]' \
'-h[Print help]' \
'--help[Print help]' \
':filename -- Filename/path of asciicast to upload:_default' \
&& ret=0
;;
(auth)
_arguments "${_arguments_options[@]}" : \
'--server-url=[asciinema server URL]:URL:_default' \
'-q[Quiet mode, i.e. suppress diagnostic messages]' \
'--quiet[Quiet mode, i.e. suppress diagnostic messages]' \
'-h[Print help]' \
'--help[Print help]' \
&& ret=0
;;
(help)
_arguments "${_arguments_options[@]}" : \
":: :_asciinema__help_commands" \
"*::: :->help" \
&& ret=0

    case $state in
    (help)
        words=($line[1] "${words[@]}")
        (( CURRENT += 1 ))
        curcontext="${curcontext%:*:*}:asciinema-help-command-$line[1]:"
        case $line[1] in
            (rec)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(play)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(stream)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(session)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(cat)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(convert)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(upload)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(auth)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(help)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
        esac
    ;;
esac
;;
        esac
    ;;
esac
}

(( $+functions[_asciinema_commands] )) ||
_asciinema_commands() {
    local commands; commands=(
'rec:Record a terminal session' \
'play:Replay a terminal session' \
'stream:Stream a terminal session' \
'session:Record and/or stream a terminal session' \
'cat:Concatenate multiple recordings' \
'convert:Convert a recording into another format' \
'upload:Upload a recording to an asciinema server' \
'auth:Authenticate this CLI with an asciinema server account' \
'help:Print this message or the help of the given subcommand(s)' \
    )
    _describe -t commands 'asciinema commands' commands "$@"
}
(( $+functions[_asciinema__auth_commands] )) ||
_asciinema__auth_commands() {
    local commands; commands=()
    _describe -t commands 'asciinema auth commands' commands "$@"
}
(( $+functions[_asciinema__cat_commands] )) ||
_asciinema__cat_commands() {
    local commands; commands=()
    _describe -t commands 'asciinema cat commands' commands "$@"
}
(( $+functions[_asciinema__convert_commands] )) ||
_asciinema__convert_commands() {
    local commands; commands=()
    _describe -t commands 'asciinema convert commands' commands "$@"
}
(( $+functions[_asciinema__help_commands] )) ||
_asciinema__help_commands() {
    local commands; commands=(
'rec:Record a terminal session' \
'play:Replay a terminal session' \
'stream:Stream a terminal session' \
'session:Record and/or stream a terminal session' \
'cat:Concatenate multiple recordings' \
'convert:Convert a recording into another format' \
'upload:Upload a recording to an asciinema server' \
'auth:Authenticate this CLI with an asciinema server account' \
'help:Print this message or the help of the given subcommand(s)' \
    )
    _describe -t commands 'asciinema help commands' commands "$@"
}
(( $+functions[_asciinema__help__auth_commands] )) ||
_asciinema__help__auth_commands() {
    local commands; commands=()
    _describe -t commands 'asciinema help auth commands' commands "$@"
}
(( $+functions[_asciinema__help__cat_commands] )) ||
_asciinema__help__cat_commands() {
    local commands; commands=()
    _describe -t commands 'asciinema help cat commands' commands "$@"
}
(( $+functions[_asciinema__help__convert_commands] )) ||
_asciinema__help__convert_commands() {
    local commands; commands=()
    _describe -t commands 'asciinema help convert commands' commands "$@"
}
(( $+functions[_asciinema__help__help_commands] )) ||
_asciinema__help__help_commands() {
    local commands; commands=()
    _describe -t commands 'asciinema help help commands' commands "$@"
}
(( $+functions[_asciinema__help__play_commands] )) ||
_asciinema__help__play_commands() {
    local commands; commands=()
    _describe -t commands 'asciinema help play commands' commands "$@"
}
(( $+functions[_asciinema__help__rec_commands] )) ||
_asciinema__help__rec_commands() {
    local commands; commands=()
    _describe -t commands 'asciinema help rec commands' commands "$@"
}
(( $+functions[_asciinema__help__session_commands] )) ||
_asciinema__help__session_commands() {
    local commands; commands=()
    _describe -t commands 'asciinema help session commands' commands "$@"
}
(( $+functions[_asciinema__help__stream_commands] )) ||
_asciinema__help__stream_commands() {
    local commands; commands=()
    _describe -t commands 'asciinema help stream commands' commands "$@"
}
(( $+functions[_asciinema__help__upload_commands] )) ||
_asciinema__help__upload_commands() {
    local commands; commands=()
    _describe -t commands 'asciinema help upload commands' commands "$@"
}
(( $+functions[_asciinema__play_commands] )) ||
_asciinema__play_commands() {
    local commands; commands=()
    _describe -t commands 'asciinema play commands' commands "$@"
}
(( $+functions[_asciinema__rec_commands] )) ||
_asciinema__rec_commands() {
    local commands; commands=()
    _describe -t commands 'asciinema rec commands' commands "$@"
}
(( $+functions[_asciinema__session_commands] )) ||
_asciinema__session_commands() {
    local commands; commands=()
    _describe -t commands 'asciinema session commands' commands "$@"
}
(( $+functions[_asciinema__stream_commands] )) ||
_asciinema__stream_commands() {
    local commands; commands=()
    _describe -t commands 'asciinema stream commands' commands "$@"
}
(( $+functions[_asciinema__upload_commands] )) ||
_asciinema__upload_commands() {
    local commands; commands=()
    _describe -t commands 'asciinema upload commands' commands "$@"
}

if [ "$funcstack[1]" = "_asciinema" ]; then
    _asciinema "$@"
else
    compdef _asciinema asciinema
fi
