#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]:SERVER_URL: ' \
'-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+[Recording file format \[default\: asciicast\]]:FORMAT:(asciicast raw txt)' \
'--format=[Recording file format \[default\: asciicast\]]:FORMAT:(asciicast raw txt)' \
'-c+[Command to record \[default\: \$SHELL\]]:COMMAND: ' \
'--command=[Command to record \[default\: \$SHELL\]]:COMMAND: ' \
'--filename=[Filename template, used when recording to a directory]:TEMPLATE: ' \
'--env=[List of env vars to save \[default\: TERM,SHELL\]]:ENV: ' \
'-t+[Title of the recording]:TITLE: ' \
'--title=[Title of the recording]:TITLE: ' \
'-i+[Limit idle time to a given number of seconds]:SECS: ' \
'--idle-time-limit=[Limit idle time to a given number of seconds]:SECS: ' \
'--tty-size=[Override terminal size for the recorded command]:COLSxROWS: ' \
'--cols=[]:COLS: ' \
'--rows=[]:ROWS: ' \
'--server-url=[asciinema server URL]:SERVER_URL: ' \
'-I[Enable input recording]' \
'--input[Enable input recording]' \
'-a[Append to an existing recording file]' \
'--append[Append to an existing recording file]' \
'--raw[]' \
'(-a --append)--overwrite[Overwrite target file if it already exists]' \
'--headless[Use headless mode - 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]' \
':path -- Output path - either a file or a directory path:' \
&& ret=0
;;
(play)
_arguments "${_arguments_options[@]}" \
'-i+[Limit idle time to a given number of seconds]:SECS: ' \
'--idle-time-limit=[Limit idle time to a given number of seconds]:SECS: ' \
'-s+[Set playback speed]:SPEED: ' \
'--speed=[Set playback speed]:SPEED: ' \
'--server-url=[asciinema server URL]:SERVER_URL: ' \
'-l[Loop loop loop loop]' \
'--loop[Loop loop loop loop]' \
'-m[Automatically pause on markers]' \
'--pause-on-markers[Automatically pause on markers]' \
'-q[Quiet mode, i.e. suppress diagnostic messages]' \
'--quiet[Quiet mode, i.e. suppress diagnostic messages]' \
'-h[Print help]' \
'--help[Print help]' \
':filename:' \
&& ret=0
;;
(stream)
_arguments "${_arguments_options[@]}" \
'-c+[Command to stream \[default\: \$SHELL\]]:COMMAND: ' \
'--command=[Command to stream \[default\: \$SHELL\]]:COMMAND: ' \
'-s+[Serve the stream with the built-in HTTP server]' \
'--serve=[Serve the stream with the built-in HTTP server]' \
'-r+[Relay the stream via an asciinema server]' \
'--relay=[Relay the stream via an asciinema server]' \
'--tty-size=[Override terminal size for the session]:COLSxROWS: ' \
'--log-file=[Log file path]:LOG_FILE:_files' \
'--server-url=[asciinema server URL]:SERVER_URL: ' \
'-I[Enable input capture]' \
'--input[Enable input capture]' \
'--headless[Use headless mode - 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]:SERVER_URL: ' \
'-q[Quiet mode, i.e. suppress diagnostic messages]' \
'--quiet[Quiet mode, i.e. suppress diagnostic messages]' \
'-h[Print help]' \
'--help[Print help]' \
'*::filename:' \
&& ret=0
;;
(convert)
_arguments "${_arguments_options[@]}" \
'-f+[Output file format \[default\: asciicast\]]:FORMAT:(asciicast raw txt)' \
'--format=[Output file format \[default\: asciicast\]]:FORMAT:(asciicast raw txt)' \
'--server-url=[asciinema server URL]:SERVER_URL: ' \
'--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:' \
':output_filename:' \
&& ret=0
;;
(upload)
_arguments "${_arguments_options[@]}" \
'--server-url=[asciinema server URL]:SERVER_URL: ' \
'-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:' \
&& ret=0
;;
(auth)
_arguments "${_arguments_options[@]}" \
'--server-url=[asciinema server URL]:SERVER_URL: ' \
'-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
;;
(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' \
'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__help__auth_commands] )) ||
_asciinema__help__auth_commands() {
    local commands; commands=()
    _describe -t commands 'asciinema help auth commands' commands "$@"
}
(( $+functions[_asciinema__cat_commands] )) ||
_asciinema__cat_commands() {
    local commands; commands=()
    _describe -t commands 'asciinema cat commands' commands "$@"
}
(( $+functions[_asciinema__help__cat_commands] )) ||
_asciinema__help__cat_commands() {
    local commands; commands=()
    _describe -t commands 'asciinema help cat commands' commands "$@"
}
(( $+functions[_asciinema__convert_commands] )) ||
_asciinema__convert_commands() {
    local commands; commands=()
    _describe -t commands 'asciinema convert 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_commands] )) ||
_asciinema__help_commands() {
    local commands; commands=(
'rec:Record a terminal session' \
'play:Replay a terminal session' \
'stream: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__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__play_commands] )) ||
_asciinema__play_commands() {
    local commands; commands=()
    _describe -t commands 'asciinema 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__rec_commands] )) ||
_asciinema__rec_commands() {
    local commands; commands=()
    _describe -t commands 'asciinema rec commands' commands "$@"
}
(( $+functions[_asciinema__help__stream_commands] )) ||
_asciinema__help__stream_commands() {
    local commands; commands=()
    _describe -t commands 'asciinema help stream commands' commands "$@"
}
(( $+functions[_asciinema__stream_commands] )) ||
_asciinema__stream_commands() {
    local commands; commands=()
    _describe -t commands 'asciinema 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__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
