# shellcheck shell=sh disable=SC2034,SC2154,SC3043

xrc:mod:lib zuz     z/utils

# Section: zip the file
___x_cmd_zuz_z(){
    [ "$#" -gt 0 ] || {
        zuz:error "Please provide filename"
        ___x_cmd_zuz -h z
        return
    }

    local ___X_CMD_ZUZ_QUIET="${___X_CMD_ZUZ_QUIET}"
    local ___X_CMD_ZUZ_ONEMODE=

    while [ $# -gt 0 ]; do
        case "$1" in
            -1)         ___X_CMD_ZUZ_ONEMODE=1; shift   ;;
            -h|--help)  ___x_cmd_zuz -h z; return       ;;
            *)          break                           ;;
        esac
    done

    local size="${size:-0}"
    local target_file="${1:-filename}";         shift
    ___x_cmd ensurefp "$target_file"

    case "$target_file" in
        *.tar)      ___x_cmd_zuz_z_tar          "$@" ;;
        *.tar.gz)   ___x_cmd_zuz_z_tgz          "$@" ;;
        *.tar.Z)    ___x_cmd_zuz_z_tarz         "$@" ;;
        *.tar.xz)   ___x_cmd_zuz_z_tar_xz       "$@" ;;
        *.tar.zst)  ___x_cmd_zuz_z_tar_zstd     "$@" ;;

        *.gz | *.bz2 | *.xz)
                    zuz:info "${target_file##*.} only support archive single file. Directory and multi file, Please use tar.${target_file##*.}"
                    ___x_cmd_zuz_z_many         "$@" ;;

        *.tgz)      ___x_cmd_zuz_z_tgz          "$@" ;;
        *.zst)      ___x_cmd_zuz_z_zstd         "$@" ;;
        *.zip)      ___x_cmd_zuz_z_zip          "$@" ;;
        *.rar)      ___x_cmd_zuz_z_rar          "$@" ;;     # Unsupported
        *.7z)       ___x_cmd_zuz_z_7z           "$@" ;;
        *.lha | *.lzh) ___x_cmd_zuz_z_lha       "$@" ;;
        *)
                    ___x_cmd_zuz --help; zuz:warn "Unsupported to compress as $target_file format.";
                    return 1
                    ;;
    esac
}
## EndSection
