Skip to content

Commit bf773dc

Browse files
authored
Merge pull request #364 from continuouspipe/feature/is-can-use-return-code
Use return codes rather than true/false transposing in functions
2 parents 43e3432 + 0832f40 commit bf773dc

File tree

9 files changed

+30
-37
lines changed

9 files changed

+30
-37
lines changed

magento2/usr/local/share/magento2/development/install.sh

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,7 @@ source "$DIR/replace_core_config_values.sh"
2323
bash "$DIR/../install_magento.sh";
2424

2525
set -x
26-
set +e
27-
IS_HEM="$(is_hem_project)"
28-
set -e
29-
if [ "$IS_HEM" == 'true' ]; then
26+
if is_hem_project; then
3027
# Run HEM
3128
export HEM_RUN_ENV="${HEM_RUN_ENV:-local}"
3229
for asset_env in $ASSET_DOWNLOAD_ENVIRONMENTS; do

magento2/usr/local/share/magento2/development/install_assets.sh

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@ set -x
1010
cd /app || exit 1
1111

1212
if [ -f "$ASSET_ARCHIVE_PATH" ]; then
13-
set +e
14-
IS_CHOWN_FORBIDDEN="$(is_chown_forbidden)"
15-
set -e
13+
IS_CHOWN_FORBIDDEN="$(run_return_boolean is_chown_forbidden)"
1614

1715
if [ "$IS_CHOWN_FORBIDDEN" != 'true' ]; then
1816
chown -R "${CODE_OWNER}:${CODE_GROUP}" pub/media

magento2/usr/local/share/magento2/install_magento.sh

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@ fi
1616

1717
cd /app || exit 1;
1818

19-
set +e
20-
IS_CHOWN_FORBIDDEN="$(is_chown_forbidden)"
21-
set -e
19+
IS_CHOWN_FORBIDDEN="$(run_return_boolean is_chown_forbidden)"
2220

2321
if [ ! -d "vendor" ] || [ ! -f "vendor/autoload.php" ]; then
2422
as_code_owner "composer config repositories.magento composer https://repo.magento.com/"

magento2/usr/local/share/magento2/install_magento_finalise.sh

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ fi
1515
cd /app || exit 1
1616

1717
set +e
18-
IS_CHOWN_FORBIDDEN="$(is_chown_forbidden)"
18+
IS_CHOWN_FORBIDDEN="$(run_return_boolean is_chown_forbidden)"
1919
set -e
2020

2121
if [ "$IS_CHOWN_FORBIDDEN" != 'true' ]; then
@@ -57,10 +57,7 @@ fi
5757
# (sad that we have to do that tho...)
5858

5959
# Download the static assets
60-
set +e
61-
IS_HEM="$(is_hem_project)"
62-
set -e
63-
if [ "$IS_HEM" == 'true' ]; then
60+
if is_hem_project; then
6461
export HEM_RUN_ENV="${HEM_RUN_ENV:-local}"
6562
for asset_env in $ASSET_DOWNLOAD_ENVIRONMENTS; do
6663
as_build "hem --non-interactive --skip-host-checks assets download -e $asset_env"

php-apache/usr/local/share/php/common_functions.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ do_composer_postinstall_scripts() {
2828
as_code_owner 'composer run-script post-install-cmd'
2929
}
3030

31-
has_composer_package() (
32-
set -e
31+
has_composer_package() {
3332
if [ ! -f "composer.lock" ]; then
3433
return
3534
fi
3635

3736
is_true "$(jq -c '(.packages + .["packages-dev"])[] | select(.name == "'"$1"'") | has("name")' composer.lock)"
38-
)
37+
return "$?"
38+
}

php-nginx/usr/local/share/php/common_functions.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ do_composer_postinstall_scripts() {
2828
as_code_owner 'composer run-script post-install-cmd'
2929
}
3030

31-
has_composer_package() (
32-
set -e
31+
has_composer_package() {
3332
if [ ! -f "composer.lock" ]; then
3433
return
3534
fi
3635

3736
is_true "$(jq -c '(.packages + .["packages-dev"])[] | select(.name == "'"$1"'") | has("name")' composer.lock)"
38-
)
37+
return "$?"
38+
}

symfony/usr/local/share/symfony/symfony_functions.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,17 @@ symfony_doctrine_mode() {
5656

5757
uses_symfony_doctrine() {
5858
[ "$(symfony_doctrine_mode)" != "off" ]
59+
return "$?"
5960
}
6061

6162
uses_symfony_doctrine_mode_schema() {
6263
[ "$(symfony_doctrine_mode)" = "schema" ]
64+
return "$?"
6365
}
6466

6567
uses_symfony_doctrine_mode_migrations() {
6668
[ "$(symfony_doctrine_mode)" = "migrations" ]
69+
return "$?"
6770
}
6871

6972
do_database_rebuild() {

ubuntu/16.04/usr/local/share/bootstrap/common_functions.sh

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,14 @@ convert_exit_code_to_string() {
8080
fi
8181
}
8282

83+
run_return_boolean() {
84+
if "$@"; then
85+
echo 'true'
86+
else
87+
echo 'false'
88+
fi
89+
}
90+
8391
convert_to_boolean_string() {
8492
if [ "$1" == '1' ] || [ "$1" == "true" ]; then
8593
echo 'true';
@@ -117,30 +125,24 @@ is_false() {
117125
}
118126

119127
is_hem_project() {
120-
local RESULT=1
121-
if [ -f /app/tools/hem/config.yaml ] || [ -f /app/tools/hobo/config.yaml ]; then
122-
RESULT=0
123-
fi
124-
convert_exit_code_to_string "$RESULT"
128+
[ -f /app/tools/hem/config.yaml ] || [ -f /app/tools/hobo/config.yaml ]
129+
return "$?"
125130
}
126131

127132
is_app_mountpoint() {
128133
grep -q -E "/app (nfs|vboxsf|fuse\\.osxfs)" /proc/mounts
129-
local RESULT="$?"
130-
convert_exit_code_to_string "$RESULT"
134+
return "$?"
131135
}
132136

133137
is_chown_forbidden() {
134138
# Determine if the app directory is an NFS mountpoint, which doesn't allow chowning.
135139
grep -q -E "/app (nfs|vboxsf)" /proc/mounts
136-
local RESULT="$?"
137-
convert_exit_code_to_string "$RESULT"
140+
return "$?"
138141
}
139142

140143
is_vboxsf_mountpoint() {
141144
grep -q "/app vboxsf" /proc/mounts
142-
local RESULT="$?"
143-
convert_exit_code_to_string "$RESULT"
145+
return "$?"
144146
}
145147

146148
alias_function() {

ubuntu/16.04/usr/local/share/env/50-bootstrap

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,14 @@ START_CRON=${START_CRON:-false}
88
START_CRON="$(convert_to_boolean_string "$START_CRON")"
99
export START_CRON
1010

11-
set +e
12-
IS_CHOWN_FORBIDDEN="$(is_chown_forbidden)"
11+
IS_CHOWN_FORBIDDEN="$(run_return_boolean is_chown_forbidden)"
1312
export IS_CHOWN_FORBIDDEN
1413

15-
IS_VBOXSF_MOUNTPOINT="$(is_vboxsf_mountpoint)"
14+
IS_VBOXSF_MOUNTPOINT="$(run_return_boolean is_vboxsf_mountpoint)"
1615
export IS_VBOXSF_MOUNTPOINT
1716

18-
IS_APP_MOUNTPOINT="$(is_app_mountpoint)"
17+
IS_APP_MOUNTPOINT="$(run_return_boolean is_app_mountpoint)"
1918
export IS_APP_MOUNTPOINT
20-
set -e
2119

2220
DEVELOPMENT_MODE="$(convert_to_boolean_string_zero_is_true "${DEVELOPMENT_MODE:-${IS_APP_MOUNTPOINT}}")"
2321
export DEVELOPMENT_MODE

0 commit comments

Comments
 (0)