summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLevente Polyak <anthraxx@archlinux.org>2024-01-18 02:29:27 +0100
committerChristian Heusel <christian@heusel.eu>2024-01-21 23:28:29 +0100
commit66e83c950cfa1c51820f04130abfacaf7c6b4c4c (patch)
tree65b85f1632a084c7832cdb66a725a2219b3a9d95
parent96f39525bf60a499aa840015159d9040b53be69a (diff)
downloaddevtools-66e83c950cfa1c51820f04130abfacaf7c6b4c4c.tar.xz
feat(version): pretty print and group together version check results
Collect all check results in arrays and pretty print the results after grouping them together based on out-of-date, up-to-date and failures. Print a summary that shows a brief statistic about the results when processing multiple check items. Component: pkgctl version check Component: pkgctl version upgrade Signed-off-by: Levente Polyak <anthraxx@archlinux.org>
-rw-r--r--src/lib/common.sh3
-rw-r--r--src/lib/version/check.sh72
-rw-r--r--src/lib/version/upgrade.sh82
3 files changed, 145 insertions, 12 deletions
diff --git a/src/lib/common.sh b/src/lib/common.sh
index a93e906..9d5622e 100644
--- a/src/lib/common.sh
+++ b/src/lib/common.sh
@@ -36,9 +36,10 @@ if [[ -t 2 && "$TERM" != dumb ]] || [[ ${DEVTOOLS_COLOR} == always ]]; then
colorize
PURPLE="$(tput setaf 5)"
DARK_GREEN="$(tput setaf 2)"
+ UNDERLINE="$(tput smul)"
else
# shellcheck disable=2034
- declare -gr ALL_OFF='' BOLD='' BLUE='' GREEN='' RED='' YELLOW='' PURPLE=''
+ declare -gr ALL_OFF='' BOLD='' BLUE='' GREEN='' RED='' YELLOW='' PURPLE='' DARK_GREEN='' UNDERLINE=''
fi
stat_busy() {
diff --git a/src/lib/version/check.sh b/src/lib/version/check.sh
index 600a346..ddd400d 100644
--- a/src/lib/version/check.sh
+++ b/src/lib/version/check.sh
@@ -39,6 +39,11 @@ pkgctl_version_check() {
local pkgbases=()
local path pkgbase upstream_version result
+ local up_to_date=()
+ local out_of_date=()
+ local failure=()
+ local section_separator=''
+
while (( $# )); do
case $1 in
-h|--help)
@@ -87,7 +92,8 @@ pkgctl_version_check() {
pkgbase=${pkgbase:-$pkgname}
if ! result=$(get_upstream_version); then
- msg_error "${pkgbase}: ${result}"
+ result="${BOLD}${pkgbase}${ALL_OFF}: ${result}"
+ failure+=("${result}")
popd >/dev/null
continue
fi
@@ -95,18 +101,49 @@ pkgctl_version_check() {
if ! result=$(vercmp "${upstream_version}" "${pkgver}"); then
result="${BOLD}${pkgbase}${ALL_OFF}: failed to compare version ${upstream_version} against ${pkgver}"
- msg_error "${result}"
-
+ failure+=("${result}")
popd >/dev/null
continue
fi
- if (( result > 0 )); then
- msg2 "New ${pkgbase} version ${upstream_version} is available upstream"
+ if (( result == 0 )); then
+ result="${BOLD}${pkgbase}${ALL_OFF}: current version ${PURPLE}${pkgver}${ALL_OFF} is latest"
+ up_to_date+=("${result}")
+ elif (( result < 0 )); then
+ result="${BOLD}${pkgbase}${ALL_OFF}: current version ${PURPLE}${pkgver}${ALL_OFF} is never than ${DARK_GREEN}${upstream_version}${ALL_OFF}"
+ up_to_date+=("${result}")
+ elif (( result > 0 )); then
+ result="${BOLD}${pkgbase}${ALL_OFF}: upgrade from version ${PURPLE}${pkgver}${ALL_OFF} to ${DARK_GREEN}${upstream_version}${ALL_OFF}"
+ out_of_date+=("${result}")
fi
popd >/dev/null
done
+
+ if (( ${#failure[@]} > 0 )); then
+ printf "%sFailure%s\n" "${section_separator}${BOLD}${UNDERLINE}" "${ALL_OFF}"
+ section_separator=$'\n'
+ for result in "${failure[@]}"; do
+ msg_error " ${result}"
+ done
+ fi
+
+ if (( ${#out_of_date[@]} > 0 )); then
+ printf "%sOut-of-date%s\n" "${section_separator}${BOLD}${UNDERLINE}" "${ALL_OFF}"
+ section_separator=$'\n'
+ for result in "${out_of_date[@]}"; do
+ msg_warn " ${result}"
+ done
+ fi
+
+ # Show summary when processing multiple packages
+ if (( ${#pkgbases[@]} > 1 )); then
+ printf '%s' "${section_separator}"
+ pkgctl_version_check_summary \
+ "${#up_to_date[@]}" \
+ "${#out_of_date[@]}" \
+ "${#failure[@]}"
+ fi
}
get_upstream_version() {
@@ -194,3 +231,28 @@ nvchecker_check_error() {
printf "%s\n" "${errors[@]}"
return 1
}
+
+pkgctl_version_check_summary() {
+ local up_to_date_count=$1
+ local out_of_date_count=$2
+ local failure_count=$3
+
+ # print nothing if all stats are zero
+ if (( up_to_date_count == 0 )) && \
+ (( out_of_date_count == 0 )) && \
+ (( failure_count == 0 )); then
+ return 0
+ fi
+
+ # print summary for all none zero stats
+ printf "%sSummary%s\n" "${BOLD}${UNDERLINE}" "${ALL_OFF}"
+ if (( up_to_date_count > 0 )); then
+ msg_success " Up-to-date: ${BOLD}${up_to_date_count}${ALL_OFF}" 2>&1
+ fi
+ if (( failure_count > 0 )); then
+ msg_error " Failure: ${BOLD}${failure_count}${ALL_OFF}" 2>&1
+ fi
+ if (( out_of_date_count > 0 )); then
+ msg_warn " Out-of-date: ${BOLD}${out_of_date_count}${ALL_OFF}" 2>&1
+ fi
+}
diff --git a/src/lib/version/upgrade.sh b/src/lib/version/upgrade.sh
index 704431a..26a5ccb 100644
--- a/src/lib/version/upgrade.sh
+++ b/src/lib/version/upgrade.sh
@@ -40,6 +40,7 @@ _EOF_
pkgctl_version_upgrade() {
local path upstream_version result
local pkgbases=()
+ local exit_code=0
while (( $# )); do
case $1 in
@@ -88,21 +89,90 @@ pkgctl_version_upgrade() {
. ./PKGBUILD
pkgbase=${pkgbase:-$pkgname}
- if ! upstream_version=$(get_upstream_version); then
- die "Failed to get latest upstream version for %s" "${pkgbase}"
+ if ! result=$(get_upstream_version); then
+ result="${BOLD}${pkgbase}${ALL_OFF}: ${result}"
+ failure+=("${result}")
+ popd >/dev/null
+ continue
fi
+ upstream_version=${result}
if ! result=$(vercmp "${upstream_version}" "${pkgver}"); then
- die "Failed to compare version %s against %s" "${upstream_version}" "${pkgver}"
+ result="${BOLD}${pkgbase}${ALL_OFF}: failed to compare version ${upstream_version} against ${pkgver}"
+ failure+=("${result}")
+ popd >/dev/null
+ continue
fi
- if (( result > 0 )); then
- msg_success "${BOLD}${pkgbase}${ALL_OFF}: upgrading from version ${PURPLE}${pkgver}${ALL_OFF} to ${DARK_GREEN}${upstream_version}${ALL_OFF}"
-
+ if (( result == 0 )); then
+ result="${BOLD}${pkgbase}${ALL_OFF}: current version ${PURPLE}${pkgver}${ALL_OFF} is latest"
+ up_to_date+=("${result}")
+ elif (( result < 0 )); then
+ result="${BOLD}${pkgbase}${ALL_OFF}: current version ${PURPLE}${pkgver}${ALL_OFF} is never than ${DARK_GREEN}${upstream_version}${ALL_OFF}"
+ up_to_date+=("${result}")
+ elif (( result > 0 )); then
+ result="${BOLD}${pkgbase}${ALL_OFF}: upgraded from version ${PURPLE}${pkgver}${ALL_OFF} to ${DARK_GREEN}${upstream_version}${ALL_OFF}"
+ out_of_date+=("${result}")
+
+ # change the PKGBUILD
pkgbuild_set_pkgver "${upstream_version}"
pkgbuild_set_pkgrel 1
fi
popd >/dev/null
done
+
+ if (( ${#failure[@]} > 0 )); then
+ exit_code=1
+ printf "%sFailure%s\n" "${section_separator}${BOLD}${UNDERLINE}" "${ALL_OFF}"
+ section_separator=$'\n'
+ for result in "${failure[@]}"; do
+ msg_error " ${result}"
+ done
+ fi
+
+ if (( ${#out_of_date[@]} > 0 )); then
+ printf "%sUpgraded%s\n" "${section_separator}${BOLD}${UNDERLINE}" "${ALL_OFF}"
+ section_separator=$'\n'
+ for result in "${out_of_date[@]}"; do
+ msg_warn " ${result}"
+ done
+ fi
+
+ # Show summary when processing multiple packages
+ if (( ${#pkgbases[@]} > 1 )); then
+ printf '%s' "${section_separator}"
+ pkgctl_version_upgrade_summary \
+ "${#up_to_date[@]}" \
+ "${#out_of_date[@]}" \
+ "${#failure[@]}"
+ fi
+
+ # return status based on results
+ return "${exit_code}"
+}
+
+pkgctl_version_upgrade_summary() {
+ local up_to_date_count=$1
+ local out_of_date_count=$2
+ local failure_count=$3
+
+ # print nothing if all stats are zero
+ if (( up_to_date_count == 0 )) && \
+ (( out_of_date_count == 0 )) && \
+ (( failure_count == 0 )); then
+ return 0
+ fi
+
+ # print summary for all none zero stats
+ printf "%sSummary%s\n" "${BOLD}${UNDERLINE}" "${ALL_OFF}"
+ if (( up_to_date_count > 0 )); then
+ msg_success " Up-to-date: ${BOLD}${up_to_date_count}${ALL_OFF}" 2>&1
+ fi
+ if (( failure_count > 0 )); then
+ msg_error " Failure: ${BOLD}${failure_count}${ALL_OFF}" 2>&1
+ fi
+ if (( out_of_date_count > 0 )); then
+ msg_warn " Upgraded: ${BOLD}${out_of_date_count}${ALL_OFF}" 2>&1
+ fi
}