#compdef arx

autoload -U is-at-least

_arx() {
    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[@]}" : \
'--generate-man-page=[]' \
'--generate-complete=[]' \
'*-v[Set verbose level. Can be specify several times to augment verbose level]' \
'*--verbose[Set verbose level. Can be specify several times to augment verbose level]' \
'-h[Print help]' \
'--help[Print help]' \
'-V[Print version]' \
'--version[Print version]' \
":: :_arx_commands" \
"*::: :->arx" \
&& ret=0
    case $state in
    (arx)
        words=($line[1] "${words[@]}")
        (( CURRENT += 1 ))
        curcontext="${curcontext%:*:*}:arx-command-$line[1]:"
        case $line[1] in
            (create)
_arguments "${_arguments_options[@]}" : \
'-o+[File path of the archive to create]:OUTFILE:_files' \
'--outfile=[File path of the archive to create]:OUTFILE:_files' \
'-C+[Move to BASE_DIR before starting adding content to arx archive.]:BASE_DIR:_files -/' \
'-L+[Get the list of files/directories to add from the FILE_LIST (incompatible with INFILES)]:FILE_LIST:_files' \
'--file-list=[Get the list of files/directories to add from the FILE_LIST (incompatible with INFILES)]:FILE_LIST:_files' \
'-c+[Set compression algorithm to use]:COMPRESSION:_default' \
'--compression=[Set compression algorithm to use]:COMPRESSION:_default' \
'-k[Keep N parents from given path]' \
'--keep-parents[Keep N parents from given path]' \
'--dir-as-root[Input dir are considered as root directory]' \
'(--no-recurse)-r[Recurse in directories]' \
'(--no-recurse)--recurse[Recurse in directories]' \
'--no-recurse[Force \`--recurse\` to be false]' \
'-1[Create only one file (default)]' \
'--one-file[Create only one file (default)]' \
'-2[Create two files (a content pack and other)]' \
'--two-files[Create two files (a content pack and other)]' \
'-N[Create mulitples files (one per pack)]' \
'--multiple-files[Create mulitples files (one per pack)]' \
'--list-compressions[List available compression algorithms]' \
'--progress[Print a progression of the creation]' \
'-f[Overwrite existing archive file]' \
'--force[Overwrite existing archive file]' \
'--follow-symlink[Follow symbolic link found in the input files]' \
'*-v[Set verbose level. Can be specify several times to augment verbose level]' \
'*--verbose[Set verbose level. Can be specify several times to augment verbose level]' \
'-h[Print help (see more with '\''--help'\'')]' \
'--help[Print help (see more with '\''--help'\'')]' \
'*::infiles -- Input files/directories:_files' \
&& ret=0
;;
(list)
_arguments "${_arguments_options[@]}" : \
'--stable-output=[Use stable output (for scripting)]:STABLE_OUTPUT:_default' \
'*-v[Set verbose level. Can be specify several times to augment verbose level]' \
'*--verbose[Set verbose level. Can be specify several times to augment verbose level]' \
'-h[Print help]' \
'--help[Print help]' \
':infile -- Archive to read:_files' \
&& ret=0
;;
(dump)
_arguments "${_arguments_options[@]}" : \
'*-v[Set verbose level. Can be specify several times to augment verbose level]' \
'*--verbose[Set verbose level. Can be specify several times to augment verbose level]' \
'-h[Print help]' \
'--help[Print help]' \
':infile -- Archive to read:_files' \
':path -- Path of the entry to print:_default' \
'::output -- Output Path. If not present or -, print to stdout:_files' \
&& ret=0
;;
(extract)
_arguments "${_arguments_options[@]}" : \
'-C+[Directory in which extract the archive. (Default to current directory)]:OUTDIR:_files -/' \
'--root-dir=[Root directory]:ROOT_DIR:_files' \
'-L+[Get the list of files/directories to extract from the FILE_LIST (incompatible with EXTRACT_FILES)]:FILE_LIST:_files' \
'--file-list=[Get the list of files/directories to extract from the FILE_LIST (incompatible with EXTRACT_FILES)]:FILE_LIST:_files' \
'-g+[Use a glob pattern to filter file to extract]:GLOB:_default' \
'--glob=[Use a glob pattern to filter file to extract]:GLOB:_default' \
'--overwrite=[How to overwrite existing files]:OVERWRITE:(skip warn newer overwrite error)' \
'-p[Print a progress bar of the extraction]' \
'--progress[Print a progress bar of the extraction]' \
'(--no-recurse)-r[Recursively extract directories]' \
'(--no-recurse)--recurse[Recursively extract directories]' \
'--no-recurse[Force \`--recurse\` to be false]' \
'*-v[Set verbose level. Can be specify several times to augment verbose level]' \
'*--verbose[Set verbose level. Can be specify several times to augment verbose level]' \
'-h[Print help (see more with '\''--help'\'')]' \
'--help[Print help (see more with '\''--help'\'')]' \
':infile -- Archive to read:_files' \
'*::extract_files -- Files to extract:_files' \
&& ret=0
;;
(mount)
_arguments "${_arguments_options[@]}" : \
'--root-dir=[Root directory]:ROOT_DIR:_files' \
'--allow-other[Share mount point with other users]' \
'--allow-root[Share mount point with root user]' \
'-f[Forground operation]' \
'--foreground[Forground operation]' \
'*-v[Set verbose level. Can be specify several times to augment verbose level]' \
'*--verbose[Set verbose level. Can be specify several times to augment verbose level]' \
'-h[Print help]' \
'--help[Print help]' \
':infile -- Archive to read:_files' \
'::mountdir -- Target directory:_files -/' \
&& ret=0
;;
(help)
_arguments "${_arguments_options[@]}" : \
":: :_arx__help_commands" \
"*::: :->help" \
&& ret=0

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

(( $+functions[_arx_commands] )) ||
_arx_commands() {
    local commands; commands=(
'create:Create an archive' \
'list:List the content in an archive' \
'dump:Print the content of an entry in the archive' \
'extract:Extract the content of an archive' \
'mount:Mount an archive in a directory' \
'help:Print this message or the help of the given subcommand(s)' \
    )
    _describe -t commands 'arx commands' commands "$@"
}
(( $+functions[_arx__create_commands] )) ||
_arx__create_commands() {
    local commands; commands=()
    _describe -t commands 'arx create commands' commands "$@"
}
(( $+functions[_arx__dump_commands] )) ||
_arx__dump_commands() {
    local commands; commands=()
    _describe -t commands 'arx dump commands' commands "$@"
}
(( $+functions[_arx__extract_commands] )) ||
_arx__extract_commands() {
    local commands; commands=()
    _describe -t commands 'arx extract commands' commands "$@"
}
(( $+functions[_arx__help_commands] )) ||
_arx__help_commands() {
    local commands; commands=(
'create:Create an archive' \
'list:List the content in an archive' \
'dump:Print the content of an entry in the archive' \
'extract:Extract the content of an archive' \
'mount:Mount an archive in a directory' \
'help:Print this message or the help of the given subcommand(s)' \
    )
    _describe -t commands 'arx help commands' commands "$@"
}
(( $+functions[_arx__help__create_commands] )) ||
_arx__help__create_commands() {
    local commands; commands=()
    _describe -t commands 'arx help create commands' commands "$@"
}
(( $+functions[_arx__help__dump_commands] )) ||
_arx__help__dump_commands() {
    local commands; commands=()
    _describe -t commands 'arx help dump commands' commands "$@"
}
(( $+functions[_arx__help__extract_commands] )) ||
_arx__help__extract_commands() {
    local commands; commands=()
    _describe -t commands 'arx help extract commands' commands "$@"
}
(( $+functions[_arx__help__help_commands] )) ||
_arx__help__help_commands() {
    local commands; commands=()
    _describe -t commands 'arx help help commands' commands "$@"
}
(( $+functions[_arx__help__list_commands] )) ||
_arx__help__list_commands() {
    local commands; commands=()
    _describe -t commands 'arx help list commands' commands "$@"
}
(( $+functions[_arx__help__mount_commands] )) ||
_arx__help__mount_commands() {
    local commands; commands=()
    _describe -t commands 'arx help mount commands' commands "$@"
}
(( $+functions[_arx__list_commands] )) ||
_arx__list_commands() {
    local commands; commands=()
    _describe -t commands 'arx list commands' commands "$@"
}
(( $+functions[_arx__mount_commands] )) ||
_arx__mount_commands() {
    local commands; commands=()
    _describe -t commands 'arx mount commands' commands "$@"
}

if [ "$funcstack[1]" = "_arx" ]; then
    _arx "$@"
else
    compdef _arx arx
fi
