summaryrefslogtreecommitdiffstats
path: root/scripts/libmakepkg
diff options
context:
space:
mode:
authorJan Alexander Steffens (heftig) <jan.steffens@gmail.com>2018-06-19 22:33:56 +0200
committerAllan McRae <allan@archlinux.org>2018-08-10 04:37:20 +0200
commit4e83abaae51c82ce6571450fb3ed9e2e71175b68 (patch)
treebc3df61153508b4cbf90b1d00a0a00dcfd2ee110 /scripts/libmakepkg
parent92bc0a474081c56d71605787d57ea2f6715a639c (diff)
downloadpacman-4e83abaae51c82ce6571450fb3ed9e2e71175b68.tar.gz
pacman-4e83abaae51c82ce6571450fb3ed9e2e71175b68.tar.xz
libmakepkg/util/option: Refactor checking to reduce code duplication
Pull out the expected=y/n check into a separate function and make use of the fact we can just prepend the fallback arrays to get the same result. Signed-off-by: Allan McRae <allan@archlinux.org>
Diffstat (limited to 'scripts/libmakepkg')
-rw-r--r--scripts/libmakepkg/util/option.sh.in77
1 files changed, 24 insertions, 53 deletions
diff --git a/scripts/libmakepkg/util/option.sh.in b/scripts/libmakepkg/util/option.sh.in
index 46e0568d..3299df9c 100644
--- a/scripts/libmakepkg/util/option.sh.in
+++ b/scripts/libmakepkg/util/option.sh.in
@@ -49,34 +49,22 @@ in_opt_array() {
##
-# Checks to see if options are present in makepkg.conf or PKGBUILD;
-# PKGBUILD options always take precedence.
-#
-# usage : check_option( $option, $expected_val )
+# usage : check_opt_array( $option, $expected_val, $haystack )
# return : 0 - matches expected
# 1 - does not match expected
# 127 - not found
##
-check_option() {
- in_opt_array "$1" ${options[@]}
- case $? in
- 0) # assert enabled
- [[ $2 = y ]]
- return ;;
- 1) # assert disabled
- [[ $2 = n ]]
- return
- esac
+check_opt_array() {
+ local option=$1 expected=$2; shift 2
- # fall back to makepkg.conf options
- in_opt_array "$1" ${OPTIONS[@]}
+ in_opt_array "$option" "$@"
case $? in
0) # assert enabled
- [[ $2 = y ]]
+ [[ $expected = y ]]
return ;;
1) # assert disabled
- [[ $2 = n ]]
- return
+ [[ $expected = n ]]
+ return ;;
esac
# not found
@@ -85,6 +73,20 @@ check_option() {
##
+# Checks to see if options are present in makepkg.conf or PKGBUILD;
+# PKGBUILD options always take precedence.
+#
+# usage : check_option( $option, $expected_val )
+# return : 0 - matches expected
+# 1 - does not match expected
+# 127 - not found
+##
+check_option() {
+ check_opt_array "$@" "${OPTIONS[@]}" "${options[@]}"
+}
+
+
+##
# Check if option is present in BUILDENV
#
# usage : check_buildenv( $option, $expected_val )
@@ -93,20 +95,10 @@ check_option() {
# 127 - not found
##
check_buildenv() {
- in_opt_array "$1" ${BUILDENV[@]}
- case $? in
- 0) # assert enabled
- [[ $2 = "y" ]]
- return ;;
- 1) # assert disabled
- [[ $2 = "n" ]]
- return ;;
- esac
-
- # not found
- return 127
+ check_opt_array "$@" "${BUILDENV[@]}"
}
+
##
# Checks to see if options are present in BUILDENV or PKGBUILD;
# PKGBUILD options always take precedence.
@@ -117,26 +109,5 @@ check_buildenv() {
# 127 - not found
##
check_buildoption() {
- in_opt_array "$1" ${options[@]}
- case $? in
- 0) # assert enabled
- [[ $2 = y ]]
- return ;;
- 1) # assert disabled
- [[ $2 = n ]]
- return
- esac
-
- in_opt_array "$1" ${BUILDENV[@]}
- case $? in
- 0) # assert enabled
- [[ $2 = y ]]
- return ;;
- 1) # assert disabled
- [[ $2 = n ]]
- return
- esac
-
- # not found
- return 127
+ check_opt_array "$@" "${BUILDENV[@]}" "${options[@]}"
}