#compdef ouch

autoload -U is-at-least

_ouch() {
    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[@]}" : \
'-f+[Specify the format of the archive]:FORMAT:_default' \
'--format=[Specify the format of the archive]:FORMAT:_default' \
'-p+[Decompress or list with password]:PASSWORD:_default' \
'--password=[Decompress or list with password]:PASSWORD:_default' \
'-c+[Concurrent working threads]:THREADS:_default' \
'--threads=[Concurrent working threads]:THREADS:_default' \
'(-n --no)-y[Skip \[Y/n\] questions, default to yes]' \
'(-n --no)--yes[Skip \[Y/n\] questions, default to yes]' \
'-n[Skip \[Y/n\] questions, default to no]' \
'--no[Skip \[Y/n\] questions, default to no]' \
'-A[Activate accessibility mode, reducing visual noise]' \
'--accessible[Activate accessibility mode, reducing visual noise]' \
'-H[Ignore hidden files]' \
'--hidden[Ignore hidden files]' \
'-q[Silence output]' \
'--quiet[Silence output]' \
'-g[Ignore files matched by git'\''s ignore files]' \
'--gitignore[Ignore files matched by git'\''s ignore files]' \
'-h[Print help (see more with '\''--help'\'')]' \
'--help[Print help (see more with '\''--help'\'')]' \
'-V[Print version]' \
'--version[Print version]' \
":: :_ouch_commands" \
"*::: :->ouch" \
&& ret=0
    case $state in
    (ouch)
        words=($line[1] "${words[@]}")
        (( CURRENT += 1 ))
        curcontext="${curcontext%:*:*}:ouch-command-$line[1]:"
        case $line[1] in
            (compress)
_arguments "${_arguments_options[@]}" : \
'-l+[Compression level, applied to all formats]:LEVEL:_default' \
'--level=[Compression level, applied to all formats]:LEVEL:_default' \
'-f+[Specify the format of the archive]:FORMAT:_default' \
'--format=[Specify the format of the archive]:FORMAT:_default' \
'-p+[Decompress or list with password]:PASSWORD:_default' \
'--password=[Decompress or list with password]:PASSWORD:_default' \
'-c+[Concurrent working threads]:THREADS:_default' \
'--threads=[Concurrent working threads]:THREADS:_default' \
'--fast[Fastest compression level possible, conflicts with --level and --slow]' \
'--slow[Slowest (and best) compression level possible, conflicts with --level and --fast]' \
'-S[Archive target files instead of storing symlinks (supported by \`tar\` and \`zip\`)]' \
'--follow-symlinks[Archive target files instead of storing symlinks (supported by \`tar\` and \`zip\`)]' \
'(-n --no)-y[Skip \[Y/n\] questions, default to yes]' \
'(-n --no)--yes[Skip \[Y/n\] questions, default to yes]' \
'-n[Skip \[Y/n\] questions, default to no]' \
'--no[Skip \[Y/n\] questions, default to no]' \
'-A[Activate accessibility mode, reducing visual noise]' \
'--accessible[Activate accessibility mode, reducing visual noise]' \
'-H[Ignore hidden files]' \
'--hidden[Ignore hidden files]' \
'-q[Silence output]' \
'--quiet[Silence output]' \
'-g[Ignore files matched by git'\''s ignore files]' \
'--gitignore[Ignore files matched by git'\''s ignore files]' \
'-h[Print help]' \
'--help[Print help]' \
'*::files -- Files to be compressed:_files' \
':output -- The resulting file. Its extensions can be used to specify the compression formats:_files' \
&& ret=0
;;
(c)
_arguments "${_arguments_options[@]}" : \
'-l+[Compression level, applied to all formats]:LEVEL:_default' \
'--level=[Compression level, applied to all formats]:LEVEL:_default' \
'-f+[Specify the format of the archive]:FORMAT:_default' \
'--format=[Specify the format of the archive]:FORMAT:_default' \
'-p+[Decompress or list with password]:PASSWORD:_default' \
'--password=[Decompress or list with password]:PASSWORD:_default' \
'-c+[Concurrent working threads]:THREADS:_default' \
'--threads=[Concurrent working threads]:THREADS:_default' \
'--fast[Fastest compression level possible, conflicts with --level and --slow]' \
'--slow[Slowest (and best) compression level possible, conflicts with --level and --fast]' \
'-S[Archive target files instead of storing symlinks (supported by \`tar\` and \`zip\`)]' \
'--follow-symlinks[Archive target files instead of storing symlinks (supported by \`tar\` and \`zip\`)]' \
'(-n --no)-y[Skip \[Y/n\] questions, default to yes]' \
'(-n --no)--yes[Skip \[Y/n\] questions, default to yes]' \
'-n[Skip \[Y/n\] questions, default to no]' \
'--no[Skip \[Y/n\] questions, default to no]' \
'-A[Activate accessibility mode, reducing visual noise]' \
'--accessible[Activate accessibility mode, reducing visual noise]' \
'-H[Ignore hidden files]' \
'--hidden[Ignore hidden files]' \
'-q[Silence output]' \
'--quiet[Silence output]' \
'-g[Ignore files matched by git'\''s ignore files]' \
'--gitignore[Ignore files matched by git'\''s ignore files]' \
'-h[Print help]' \
'--help[Print help]' \
'*::files -- Files to be compressed:_files' \
':output -- The resulting file. Its extensions can be used to specify the compression formats:_files' \
&& ret=0
;;
(decompress)
_arguments "${_arguments_options[@]}" : \
'-d+[Place results in a directory other than the current one]:OUTPUT_DIR:_files' \
'--dir=[Place results in a directory other than the current one]:OUTPUT_DIR:_files' \
'-f+[Specify the format of the archive]:FORMAT:_default' \
'--format=[Specify the format of the archive]:FORMAT:_default' \
'-p+[Decompress or list with password]:PASSWORD:_default' \
'--password=[Decompress or list with password]:PASSWORD:_default' \
'-c+[Concurrent working threads]:THREADS:_default' \
'--threads=[Concurrent working threads]:THREADS:_default' \
'-r[Remove the source file after successful decompression]' \
'--remove[Remove the source file after successful decompression]' \
'(-n --no)-y[Skip \[Y/n\] questions, default to yes]' \
'(-n --no)--yes[Skip \[Y/n\] questions, default to yes]' \
'-n[Skip \[Y/n\] questions, default to no]' \
'--no[Skip \[Y/n\] questions, default to no]' \
'-A[Activate accessibility mode, reducing visual noise]' \
'--accessible[Activate accessibility mode, reducing visual noise]' \
'-H[Ignore hidden files]' \
'--hidden[Ignore hidden files]' \
'-q[Silence output]' \
'--quiet[Silence output]' \
'-g[Ignore files matched by git'\''s ignore files]' \
'--gitignore[Ignore files matched by git'\''s ignore files]' \
'-h[Print help]' \
'--help[Print help]' \
'*::files -- Files to be decompressed, or "-" for stdin:_files' \
&& ret=0
;;
(d)
_arguments "${_arguments_options[@]}" : \
'-d+[Place results in a directory other than the current one]:OUTPUT_DIR:_files' \
'--dir=[Place results in a directory other than the current one]:OUTPUT_DIR:_files' \
'-f+[Specify the format of the archive]:FORMAT:_default' \
'--format=[Specify the format of the archive]:FORMAT:_default' \
'-p+[Decompress or list with password]:PASSWORD:_default' \
'--password=[Decompress or list with password]:PASSWORD:_default' \
'-c+[Concurrent working threads]:THREADS:_default' \
'--threads=[Concurrent working threads]:THREADS:_default' \
'-r[Remove the source file after successful decompression]' \
'--remove[Remove the source file after successful decompression]' \
'(-n --no)-y[Skip \[Y/n\] questions, default to yes]' \
'(-n --no)--yes[Skip \[Y/n\] questions, default to yes]' \
'-n[Skip \[Y/n\] questions, default to no]' \
'--no[Skip \[Y/n\] questions, default to no]' \
'-A[Activate accessibility mode, reducing visual noise]' \
'--accessible[Activate accessibility mode, reducing visual noise]' \
'-H[Ignore hidden files]' \
'--hidden[Ignore hidden files]' \
'-q[Silence output]' \
'--quiet[Silence output]' \
'-g[Ignore files matched by git'\''s ignore files]' \
'--gitignore[Ignore files matched by git'\''s ignore files]' \
'-h[Print help]' \
'--help[Print help]' \
'*::files -- Files to be decompressed, or "-" for stdin:_files' \
&& ret=0
;;
(list)
_arguments "${_arguments_options[@]}" : \
'-f+[Specify the format of the archive]:FORMAT:_default' \
'--format=[Specify the format of the archive]:FORMAT:_default' \
'-p+[Decompress or list with password]:PASSWORD:_default' \
'--password=[Decompress or list with password]:PASSWORD:_default' \
'-c+[Concurrent working threads]:THREADS:_default' \
'--threads=[Concurrent working threads]:THREADS:_default' \
'-t[Show archive contents as a tree]' \
'--tree[Show archive contents as a tree]' \
'(-n --no)-y[Skip \[Y/n\] questions, default to yes]' \
'(-n --no)--yes[Skip \[Y/n\] questions, default to yes]' \
'-n[Skip \[Y/n\] questions, default to no]' \
'--no[Skip \[Y/n\] questions, default to no]' \
'-A[Activate accessibility mode, reducing visual noise]' \
'--accessible[Activate accessibility mode, reducing visual noise]' \
'-H[Ignore hidden files]' \
'--hidden[Ignore hidden files]' \
'-q[Silence output]' \
'--quiet[Silence output]' \
'-g[Ignore files matched by git'\''s ignore files]' \
'--gitignore[Ignore files matched by git'\''s ignore files]' \
'-h[Print help]' \
'--help[Print help]' \
'*::archives -- Archives whose contents should be listed:_files' \
&& ret=0
;;
(l)
_arguments "${_arguments_options[@]}" : \
'-f+[Specify the format of the archive]:FORMAT:_default' \
'--format=[Specify the format of the archive]:FORMAT:_default' \
'-p+[Decompress or list with password]:PASSWORD:_default' \
'--password=[Decompress or list with password]:PASSWORD:_default' \
'-c+[Concurrent working threads]:THREADS:_default' \
'--threads=[Concurrent working threads]:THREADS:_default' \
'-t[Show archive contents as a tree]' \
'--tree[Show archive contents as a tree]' \
'(-n --no)-y[Skip \[Y/n\] questions, default to yes]' \
'(-n --no)--yes[Skip \[Y/n\] questions, default to yes]' \
'-n[Skip \[Y/n\] questions, default to no]' \
'--no[Skip \[Y/n\] questions, default to no]' \
'-A[Activate accessibility mode, reducing visual noise]' \
'--accessible[Activate accessibility mode, reducing visual noise]' \
'-H[Ignore hidden files]' \
'--hidden[Ignore hidden files]' \
'-q[Silence output]' \
'--quiet[Silence output]' \
'-g[Ignore files matched by git'\''s ignore files]' \
'--gitignore[Ignore files matched by git'\''s ignore files]' \
'-h[Print help]' \
'--help[Print help]' \
'*::archives -- Archives whose contents should be listed:_files' \
&& ret=0
;;
(ls)
_arguments "${_arguments_options[@]}" : \
'-f+[Specify the format of the archive]:FORMAT:_default' \
'--format=[Specify the format of the archive]:FORMAT:_default' \
'-p+[Decompress or list with password]:PASSWORD:_default' \
'--password=[Decompress or list with password]:PASSWORD:_default' \
'-c+[Concurrent working threads]:THREADS:_default' \
'--threads=[Concurrent working threads]:THREADS:_default' \
'-t[Show archive contents as a tree]' \
'--tree[Show archive contents as a tree]' \
'(-n --no)-y[Skip \[Y/n\] questions, default to yes]' \
'(-n --no)--yes[Skip \[Y/n\] questions, default to yes]' \
'-n[Skip \[Y/n\] questions, default to no]' \
'--no[Skip \[Y/n\] questions, default to no]' \
'-A[Activate accessibility mode, reducing visual noise]' \
'--accessible[Activate accessibility mode, reducing visual noise]' \
'-H[Ignore hidden files]' \
'--hidden[Ignore hidden files]' \
'-q[Silence output]' \
'--quiet[Silence output]' \
'-g[Ignore files matched by git'\''s ignore files]' \
'--gitignore[Ignore files matched by git'\''s ignore files]' \
'-h[Print help]' \
'--help[Print help]' \
'*::archives -- Archives whose contents should be listed:_files' \
&& ret=0
;;
(help)
_arguments "${_arguments_options[@]}" : \
":: :_ouch__help_commands" \
"*::: :->help" \
&& ret=0

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

(( $+functions[_ouch_commands] )) ||
_ouch_commands() {
    local commands; commands=(
'compress:Compress one or more files into one output file' \
'c:Compress one or more files into one output file' \
'decompress:Decompresses one or more files, optionally into another folder' \
'd:Decompresses one or more files, optionally into another folder' \
'list:List contents of an archive' \
'l:List contents of an archive' \
'ls:List contents of an archive' \
'help:Print this message or the help of the given subcommand(s)' \
    )
    _describe -t commands 'ouch commands' commands "$@"
}
(( $+functions[_ouch__compress_commands] )) ||
_ouch__compress_commands() {
    local commands; commands=()
    _describe -t commands 'ouch compress commands' commands "$@"
}
(( $+functions[_ouch__decompress_commands] )) ||
_ouch__decompress_commands() {
    local commands; commands=()
    _describe -t commands 'ouch decompress commands' commands "$@"
}
(( $+functions[_ouch__help_commands] )) ||
_ouch__help_commands() {
    local commands; commands=(
'compress:Compress one or more files into one output file' \
'decompress:Decompresses one or more files, optionally into another folder' \
'list:List contents of an archive' \
'help:Print this message or the help of the given subcommand(s)' \
    )
    _describe -t commands 'ouch help commands' commands "$@"
}
(( $+functions[_ouch__help__compress_commands] )) ||
_ouch__help__compress_commands() {
    local commands; commands=()
    _describe -t commands 'ouch help compress commands' commands "$@"
}
(( $+functions[_ouch__help__decompress_commands] )) ||
_ouch__help__decompress_commands() {
    local commands; commands=()
    _describe -t commands 'ouch help decompress commands' commands "$@"
}
(( $+functions[_ouch__help__help_commands] )) ||
_ouch__help__help_commands() {
    local commands; commands=()
    _describe -t commands 'ouch help help commands' commands "$@"
}
(( $+functions[_ouch__help__list_commands] )) ||
_ouch__help__list_commands() {
    local commands; commands=()
    _describe -t commands 'ouch help list commands' commands "$@"
}
(( $+functions[_ouch__list_commands] )) ||
_ouch__list_commands() {
    local commands; commands=()
    _describe -t commands 'ouch list commands' commands "$@"
}

if [ "$funcstack[1]" = "_ouch" ]; then
    _ouch "$@"
else
    compdef _ouch ouch
fi
