#compdef lief-patchelf

autoload -U is-at-least

_lief-patchelf() {
    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[@]}" : \
'--set-interpreter=[Change the dynamic loader ('\''ELF interpreter'\'') of executable given to INTERPRETER.]:INTERPRETER:_default' \
'--page-size=[Uses the given page size instead of the default]:SIZE:_default' \
'--set-os-abi=[Changes the OS ABI of the executable (\`EI_OSABI\` field of an ELF file).]: :_default' \
'--set-soname=[Sets DT_SONAME entry of a library to SONAME.]:SONAME:_default' \
'--set-rpath=[Change the \`DT_RUNPATH\` of the executable or library to RUNPATH.]:RUNPATH:_default' \
'*--add-rpath=[Add RUNPATH to the existing DT_RUNPATH of the executable or library.]:RUNPATH:_default' \
'*--allowed-rpath-prefixes=[]:PREFIXES:_default' \
'*--add-needed=[Adds a declared dependency on a dynamic library (DT_NEEDED). This option can be given multiple times.]:LIBRARY:_default' \
'*--remove-needed=[Removes a declared dependency on LIBRARY (DT_NEEDED entry). This option can be given multiple times.]:LIBRARY:_default' \
'*--replace-needed=[Replaces a declared dependency on a dynamic library with another one (DT_NEEDED).This option can be given multiple times.]:LIB_ORIG:_default:LIB_ORIG:_default' \
'*--clear-symbol-version=[Clear the symbol version requirement for the given symbol name. This option can be given multiple times. ]: :_default' \
'*--remove-needed-version=[Removes VERSION_SYMBOL from LIBRARY in .gnu.version_r and resets entries referenced the version in .gnu.version, could be used to remove symbol versioning. LIBRARY and VERSION_SYMBOL can be retrieved from the output of \`readelf -V\`. ]:LIBRARY:_default:LIBRARY:_default' \
'-o+[]: :_files' \
'--output=[]: :_files' \
'--rename-dynamic-symbols=[Renames dynamic symbols]: :_files' \
'--generate=[]: :(bash elvish fish powershell zsh)' \
'--generate-manpage=[]: :_files' \
'--print-interpreter[Prints the ELF interpreter of the executable. (e.g. \`/lib64/ld-linux-x86-64.so.2\`)]' \
'--print-os-abi[Prints the OS ABI of the executable (\`EI_OSABI\` field of an ELF file).]' \
'--print-soname[Prints DT_SONAME entry of .dynamic section. Raises an error if DT_SONAME doesn'\''t exist. ]' \
'--print-rpath[Prints the DT_RUNPATH or DT_RPATH for an executable or library.]' \
'--shrink-rpath[Remove from the DT_RUNPATH or DT_RPATH all directories that do not contain a library referenced by DT_NEEDED fields of the executable or library. ]' \
'--remove-rpath[Removes the DT_RPATH or DT_RUNPATH entry of the executable or library.]' \
'--force-rpath[Forces the use of the obsolete DT_RPATH in the file instead of DT_RUNPATH By default DT_RPATH is converted to DT_RUNPATH.]' \
'--print-needed[Prints all DT_NEEDED entries of the executable.]' \
'--print-execstack[Prints the state of the executable flag of the GNU_STACK program header, if present.]' \
'--clear-execstack[Clears the executable flag of the GNU_STACK program header, or adds a new header.]' \
'--set-execstack[Sets the executable flag of the GNU_STACK program header, or adds a new header.]' \
'--no-sort[]' \
'--debug[Prints details of the changes made to the input file.]' \
'--no-default-lib[Marks the object so that the search for dependencies of this object will ignore any default library search paths.]' \
'--no-clobber-old-sections[]' \
'--add-debug-tag[Adds DT_DEBUG tag to the \`.dynamic\` section]' \
'-h[Print help (see more with '\''--help'\'')]' \
'--help[Print help (see more with '\''--help'\'')]' \
'-V[Print version]' \
'--version[Print version]' \
'*::filenames:_files' \
&& ret=0
}

(( $+functions[_lief-patchelf_commands] )) ||
_lief-patchelf_commands() {
    local commands; commands=()
    _describe -t commands 'lief-patchelf commands' commands "$@"
}

if [ "$funcstack[1]" = "_lief-patchelf" ]; then
    _lief-patchelf "$@"
else
    compdef _lief-patchelf lief-patchelf
fi
