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>
This commit is contained in:
parent
92bc0a4740
commit
4e83abaae5
1 changed files with 28 additions and 57 deletions
|
@ -48,6 +48,30 @@ in_opt_array() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
##
|
||||||
|
# usage : check_opt_array( $option, $expected_val, $haystack )
|
||||||
|
# return : 0 - matches expected
|
||||||
|
# 1 - does not match expected
|
||||||
|
# 127 - not found
|
||||||
|
##
|
||||||
|
check_opt_array() {
|
||||||
|
local option=$1 expected=$2; shift 2
|
||||||
|
|
||||||
|
in_opt_array "$option" "$@"
|
||||||
|
case $? in
|
||||||
|
0) # assert enabled
|
||||||
|
[[ $expected = y ]]
|
||||||
|
return ;;
|
||||||
|
1) # assert disabled
|
||||||
|
[[ $expected = n ]]
|
||||||
|
return ;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
# not found
|
||||||
|
return 127
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
##
|
##
|
||||||
# Checks to see if options are present in makepkg.conf or PKGBUILD;
|
# Checks to see if options are present in makepkg.conf or PKGBUILD;
|
||||||
# PKGBUILD options always take precedence.
|
# PKGBUILD options always take precedence.
|
||||||
|
@ -58,29 +82,7 @@ in_opt_array() {
|
||||||
# 127 - not found
|
# 127 - not found
|
||||||
##
|
##
|
||||||
check_option() {
|
check_option() {
|
||||||
in_opt_array "$1" ${options[@]}
|
check_opt_array "$@" "${OPTIONS[@]}" "${options[@]}"
|
||||||
case $? in
|
|
||||||
0) # assert enabled
|
|
||||||
[[ $2 = y ]]
|
|
||||||
return ;;
|
|
||||||
1) # assert disabled
|
|
||||||
[[ $2 = n ]]
|
|
||||||
return
|
|
||||||
esac
|
|
||||||
|
|
||||||
# fall back to makepkg.conf options
|
|
||||||
in_opt_array "$1" ${OPTIONS[@]}
|
|
||||||
case $? in
|
|
||||||
0) # assert enabled
|
|
||||||
[[ $2 = y ]]
|
|
||||||
return ;;
|
|
||||||
1) # assert disabled
|
|
||||||
[[ $2 = n ]]
|
|
||||||
return
|
|
||||||
esac
|
|
||||||
|
|
||||||
# not found
|
|
||||||
return 127
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -93,20 +95,10 @@ check_option() {
|
||||||
# 127 - not found
|
# 127 - not found
|
||||||
##
|
##
|
||||||
check_buildenv() {
|
check_buildenv() {
|
||||||
in_opt_array "$1" ${BUILDENV[@]}
|
check_opt_array "$@" "${BUILDENV[@]}"
|
||||||
case $? in
|
|
||||||
0) # assert enabled
|
|
||||||
[[ $2 = "y" ]]
|
|
||||||
return ;;
|
|
||||||
1) # assert disabled
|
|
||||||
[[ $2 = "n" ]]
|
|
||||||
return ;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
# not found
|
|
||||||
return 127
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
##
|
##
|
||||||
# Checks to see if options are present in BUILDENV or PKGBUILD;
|
# Checks to see if options are present in BUILDENV or PKGBUILD;
|
||||||
# PKGBUILD options always take precedence.
|
# PKGBUILD options always take precedence.
|
||||||
|
@ -117,26 +109,5 @@ check_buildenv() {
|
||||||
# 127 - not found
|
# 127 - not found
|
||||||
##
|
##
|
||||||
check_buildoption() {
|
check_buildoption() {
|
||||||
in_opt_array "$1" ${options[@]}
|
check_opt_array "$@" "${BUILDENV[@]}" "${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
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue