Skip to content

Commit b590673

Browse files
author
Daniel Ruthardt
committed
🛠️ Refactor variable handling
Use variables when it does make sense; try to use local variables as much as possible. Do not use variables when the value isn't actually re-used and thus not necessary. Signed-off-by: Daniel Ruthardt <druthardt@linuxfoundation.org>
1 parent e6174f8 commit b590673

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

bashpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ set -e
6161
# directory to prevent it from being accidentally committed to version control.
6262
function include() {
6363
local include=$1
64-
local package=${include%%/*}
6564

6665
local path
6766
IFS=:; for directory in $BASHP_INCLUDE_DIRS; do
@@ -70,9 +69,13 @@ function include() {
7069
done
7170

7271
if [[ ! -f "$path" ]] && command -v docker &>/dev/null; then
72+
local repository
7373
IFS=:; for repository in $BASHP_INCLUDE_REPOS; do
74-
if docker manifest inspect "$repository/bashp-$package:latest" &>/dev/null; then
75-
id=$(docker create "$repository/bashp-$package:latest" none)
74+
local package=${include%%/*}
75+
local image="$repository/bashp-$package:latest"
76+
if docker manifest inspect "$image" &>/dev/null; then
77+
local id
78+
id=$(docker create "$image" none)
7679
mkdir -p "$INCLUDE_DIR/$package"
7780
docker cp "$id:/$include" "$INCLUDE_DIR/$include"
7881
docker rm "$id"
@@ -142,16 +145,12 @@ function preprocess() {
142145
case "$line" in
143146
*::*)
144147
if [[ "$line" =~ ([a-zA-Z0-9_]+)::([a-zA-Z0-9_]+) ]]; then
145-
local package="${BASH_REMATCH[1]}"
146-
local function="${BASH_REMATCH[2]}"
147-
local include="${package}/${function}"
148-
include_once "$include"
148+
include_once "${BASH_REMATCH[1]}/${BASH_REMATCH[2]}"
149149
fi
150150
echo "$line"
151151
;;
152152
"#include "*)
153-
local include=${line#*#include }
154-
include_once "$include"
153+
include_once ${line#*#include }
155154
;;
156155
*) echo "$line" ;;
157156
esac

0 commit comments

Comments
 (0)