Pack : Use _iterate_targets.

This commit is contained in:
Dmitry Voronin 2023-12-17 20:22:06 +03:00
parent 47a30351d1
commit 418f146141

View file

@ -18,15 +18,13 @@ function pack() {
# report no format.
if [[ "${format}" = "" ]]; then
echo "Could not determine output format."
_error "Could not determine output format."
help pack
return 2
fi
# All targets by default.
if [[ "${targets}" = "" ]]; then
targets=(*)
fi
[[ "${targets}" = "" ]] && targets=(*)
# process.
case "${format}" in
@ -49,15 +47,12 @@ function pack() {
_pack_xz "${output}" "${targets[@]}"
;;
*)
echo -e "${color_bred}${target}: Format not supported.${color_default}"
return 1
_error "${target}: Format not supported."
return 2
;;
esac
# Show error.
if [[ $? != 0 ]]; then
echo -e "${color_bred}${target}: Failed.${color_default}"
fi
_iterate_targets process ${targets[@]}
}
# Attempt to unpack.
@ -65,28 +60,10 @@ function pack() {
# Usage: unpack [FILES]
function unpack() {
local IFS=$'\n'
local targets=("${@}")
local count=0
local total=${#targets[@]}
local failed=0
# All targets by default.
if [[ "${targets}" = "" ]]; then
targets=($(ls | grep -E ${_unpack_supported}))
total=${#targets[@]}
fi
# process all files.
for target in "${targets[@]}"; do
# increment counter.
((count++))
# prepare status.
local status="[${count}/${total}] ${target}"
# show status.
echo -e "${status}"
local targets=(${@})
[[ "${targets}" = "" ]] && targets=($(_ls_files | grep -E ${_unpack_supported}))
process() {
# unpack file type.
local type="${target##*.}"
@ -123,23 +100,13 @@ function unpack() {
_unpack_gz "${target}"
;;
*)
echo -e "${color_bred}${target}: Format not supported.${color_default}"
((failed++))
continue
_error "${target}: Format not supported."
return 2
;;
esac
}
# actions on error.
if [[ $? != 0 ]]; then
echo -e "${color_bred}${target}: Failed.${color_default}"
((failed++))
fi
done
if [[ ${failed} != 0 ]]; then
echo -e "${color_bred}Failed: ${failed}.${color_default}"
false
fi
_iterate_targets process ${targets[@]}
}
function _pack_zip() {