Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLevente Polyak <anthraxx@archlinux.org>2024-01-18 19:15:22 +0100
committerLevente Polyak <anthraxx@archlinux.org>2024-01-22 19:45:10 +0100
commite3edf25554c78e28679b100e24c55c87ee65a22d (patch)
treeb630bf07cc736fe986140154bb8f576e62afe9d4 /src
parentb258bb3b7c55d06bad108400450acd32cff05366 (diff)
feat(version): use exit code for check to indicate out-of-date versions
It can be handy to have an exit code that allows better status indication or chaining. On exit, return one of the following codes: - 0: Normal exit condition, all checked versions are up-to-date - 1: Unknown cause of failure - 2: Normal exit condition, but there are out-of-date versions - 3: Failed to run some version checks Component: pkgctl version check Signed-off-by: Levente Polyak <anthraxx@archlinux.org>
Diffstat (limited to 'src')
-rw-r--r--src/lib/version.sh4
-rw-r--r--src/lib/version/check.sh14
2 files changed, 16 insertions, 2 deletions
diff --git a/src/lib/version.sh b/src/lib/version.sh
index 14cd810..4340fca 100644
--- a/src/lib/version.sh
+++ b/src/lib/version.sh
@@ -47,7 +47,7 @@ pkgctl_version() {
# shellcheck source=src/lib/version/check.sh
source "${_DEVTOOLS_LIBRARY_DIR}"/lib/version/check.sh
pkgctl_version_check "$@"
- exit 0
+ exit $?
;;
upgrade)
_DEVTOOLS_COMMAND+=" $1"
@@ -55,7 +55,7 @@ pkgctl_version() {
# shellcheck source=src/lib/version/upgrade.sh
source "${_DEVTOOLS_LIBRARY_DIR}"/lib/version/upgrade.sh
pkgctl_version_upgrade "$@"
- exit 0
+ exit $?
;;
*)
die "invalid argument: %s" "$1"
diff --git a/src/lib/version/check.sh b/src/lib/version/check.sh
index 9bc29c1..cc8827d 100644
--- a/src/lib/version/check.sh
+++ b/src/lib/version/check.sh
@@ -15,6 +15,14 @@ source /usr/share/makepkg/util/message.sh
set -eo pipefail
+readonly PKGCTL_VERSION_CHECK_EXIT_UP_TO_DATE=0
+export PKGCTL_VERSION_CHECK_EXIT_UP_TO_DATE
+readonly PKGCTL_VERSION_CHECK_EXIT_OUT_OF_DATE=2
+export PKGCTL_VERSION_CHECK_EXIT_OUT_OF_DATE
+readonly PKGCTL_VERSION_CHECK_EXIT_FAILURE=3
+export PKGCTL_VERSION_CHECK_EXIT_FAILURE
+
+
pkgctl_version_check_usage() {
local -r COMMAND=${_DEVTOOLS_COMMAND:-${BASH_SOURCE[0]##*/}}
cat <<- _EOF_
@@ -48,6 +56,7 @@ pkgctl_version_check() {
local failure=()
local current_item=0
local section_separator=''
+ local exit_code=${PKGCTL_VERSION_CHECK_EXIT_UP_TO_DATE}
while (( $# )); do
case $1 in
@@ -160,6 +169,7 @@ pkgctl_version_check() {
fi
if (( ${#failure[@]} > 0 )); then
+ exit_code=${PKGCTL_VERSION_CHECK_EXIT_FAILURE}
printf "%sFailure%s\n" "${section_separator}${BOLD}${UNDERLINE}" "${ALL_OFF}"
section_separator=$'\n'
for result in "${failure[@]}"; do
@@ -168,6 +178,7 @@ pkgctl_version_check() {
fi
if (( ${#out_of_date[@]} > 0 )); then
+ exit_code=${PKGCTL_VERSION_CHECK_EXIT_OUT_OF_DATE}
printf "%sOut-of-date%s\n" "${section_separator}${BOLD}${UNDERLINE}" "${ALL_OFF}"
section_separator=$'\n'
for result in "${out_of_date[@]}"; do
@@ -183,6 +194,9 @@ pkgctl_version_check() {
"${#out_of_date[@]}" \
"${#failure[@]}"
fi
+
+ # return status based on results
+ return "${exit_code}"
}
get_upstream_version() {