Skip to content

Commit 5d3a0c5

Browse files
authored
Make foreach-bundle a proper shell script
1 parent 1b06f0f commit 5d3a0c5

File tree

1 file changed

+20
-16
lines changed

1 file changed

+20
-16
lines changed

foreach-bundle

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,24 @@
11
#!/usr/bin/env bash
2+
#
3+
# Execute a command in each subfolder.
4+
#
25

3-
BUNDLE_DEPENDENCIES=$(curl --silent https://raw.githubusercontent.com/wp-cli/wp-cli-bundle/master/composer.json -q | jq '.["require"] | keys[]' )
4-
BUNDLE_DEPENDENCIES=$(echo "wp-cli/wp-cli-bundle $BUNDLE_DEPENDENCIES")
6+
get_bundle_dependencies()
7+
{
8+
echo "wp-cli/wp-cli-bundle"
9+
curl --silent "https://raw.githubusercontent.com/wp-cli/wp-cli-bundle/master/composer.json" \
10+
| jq --raw-output '."require" | keys[] | select(startswith("wp-cli/"))'
11+
}
512

6-
for NAME in $BUNDLE_DEPENDENCIES; do
7-
8-
REPO=$(echo $NAME | tr -d '"')
9-
case $REPO in wp-cli/*)
10-
export REPO=$(echo "$REPO" | sed -e "s|^wp-cli/||")
11-
if [ -d "$REPO" ]; then
12-
OLDPWD="$(pwd)"
13-
cd "$REPO"
14-
echo "--- $REPO : ---"
15-
"$@"
16-
cd "$OLDPWD"
17-
fi
18-
esac
19-
done
13+
while read -r dependency; do
14+
# Remove wp-cli/ prefix
15+
repo_path="${dependency:7}"
16+
if [ ! -d "${repo_path}" ]; then
17+
continue
18+
fi
2019

20+
echo "--- ${repo_path}: ---"
21+
cd "${repo_path}"
22+
bash -c "$@"
23+
cd -
24+
done <<< "$(get_bundle_dependencies)"

0 commit comments

Comments
 (0)