#compdef install

autoload -U is-at-least

_install() {
    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[@]}" : \
'--backup=[make a backup of each existing destination file]::CONTROL:_default' \
'-g+[set group ownership, instead of process'\''s current group]:GROUP:_default' \
'--group=[set group ownership, instead of process'\''s current group]:GROUP:_default' \
'-m+[set permission mode (as in chmod), instead of rwxr-xr-x]:MODE:_default' \
'--mode=[set permission mode (as in chmod), instead of rwxr-xr-x]:MODE:_default' \
'-o+[set ownership (super-user only)]:OWNER:_users' \
'--owner=[set ownership (super-user only)]:OWNER:_users' \
'--strip-program=[program used to strip binaries]:PROGRAM:_command_names -e' \
'-S+[override the usual backup suffix]:SUFFIX:_default' \
'--suffix=[override the usual backup suffix]:SUFFIX:_default' \
'-t+[move all SOURCE arguments into DIRECTORY]:DIRECTORY:_files -/' \
'--target-directory=[move all SOURCE arguments into DIRECTORY]:DIRECTORY:_files -/' \
'--context=[set security context of files and directories]::CONTEXT:_default' \
'-b[like --backup but does not accept an argument]' \
'-c[ignored]' \
'-C[compare each pair of source and destination files, and in some cases, do not modify the destination at all]' \
'--compare[compare each pair of source and destination files, and in some cases, do not modify the destination at all]' \
'-d[treat all arguments as directory names. create all components of the specified directories]' \
'--directory[treat all arguments as directory names. create all components of the specified directories]' \
'-D[create all leading components of DEST except the last, then copy SOURCE to DEST]' \
'-p[apply access/modification times of SOURCE files to corresponding destination files]' \
'--preserve-timestamps[apply access/modification times of SOURCE files to corresponding destination files]' \
'-s[strip symbol tables]' \
'--strip[strip symbol tables]' \
'-T[treat DEST as a normal file]' \
'--no-target-directory[treat DEST as a normal file]' \
'-v[explain what is being done]' \
'--verbose[explain what is being done]' \
'-P[preserve security context]' \
'--preserve-context[preserve security context]' \
'-Z[set SELinux security context of destination file and each created directory to default type]' \
'-U[do not require elevated privileges to change the owner, the group, or the file flags of the destination]' \
'--unprivileged[do not require elevated privileges to change the owner, the group, or the file flags of the destination]' \
'-h[Print help]' \
'--help[Print help]' \
'-V[Print version]' \
'--version[Print version]' \
'*::files:_files' \
&& ret=0
}

(( $+functions[_install_commands] )) ||
_install_commands() {
    local commands; commands=()
    _describe -t commands 'install commands' commands "$@"
}

if [ "$funcstack[1]" = "_install" ]; then
    _install "$@"
else
    compdef _install install
fi
