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

# Section: unzip the zip file

xrc:mod:lib     zuz     uz/files  uz/onefile  uz/wholefile

# Reference: https://linuxhint.com/xz_compression_tutorial/
# Reference: https://blog.csdn.net/example440982/article/details/51712973
# Reference: https://wangying.sinaapp.com/archives/2574
___x_cmd_zuz_uz(){
    [ "$#" -gt 0 ] || {
        zuz:error "No argument provide."
        ___x_cmd_zuz -h uz
        return
    }

    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 uz; return       ;;
            *)          break                           ;;
        esac
    done

    local target_file="${1}"
    local dest_folder="${2:-.}"
    local ___X_CMD_ZUZ_QUIET="${___X_CMD_ZUZ_QUIET}"
    shift $#

    target_file="$( ___x_cmd_cmds_cd "$(dirname "$target_file")" && pwd )"/$(basename "$target_file")
    ___x_cmd_cmds_mkdir -p "$dest_folder"

    (
        ___x_cmd_cmds_cd "$dest_folder" || return 1

        if [ "$___X_CMD_ZUZ_ONEMODE" = 1 ];then     ___x_cmd_zuz_uz_one_file  "$@"
        elif [ "$#" -gt 0 ]; then                   ___x_cmd_zuz_uz_and_files "$@"
        else                                        ___x_cmd_zuz_uz_whole_file
        fi

        local exit_code="$?"
        if [ -n "$ZUZ_DELETE_AFTER" ]; then
            [ "$exit_code" = 0 ] && ___x_cmd_cmds_rm "$target_file"
        else
            return $exit_code
        fi
    )
}

___x_cmd_zuz_uzr(){
    ZUZ_DELETE_AFTER=1 ___x_cmd_zuz_uz "$@"
}
## EndSection

