mirror of
https://github.com/tests-always-included/mo.git
synced 2024-12-23 01:52:22 +00:00
Adding example to illustrate how to get properties
This is supporting information to demonstrate one way to address the user's issues - see issue #5.
This commit is contained in:
parent
5810520546
commit
140d4ec350
39
demo/function-for-advanced-looping
Executable file
39
demo/function-for-advanced-looping
Executable file
@ -0,0 +1,39 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
cd "$(dirname "$0")" # Go to the script's directory
|
||||||
|
|
||||||
|
EVERY_REPO() {
|
||||||
|
echo "# Starting EVERY_REPO"
|
||||||
|
|
||||||
|
# Get list of repos
|
||||||
|
for REPO in "${REPOS[@]}"; do
|
||||||
|
echo "## Looping one time for repo: $REPO"
|
||||||
|
|
||||||
|
# String replace REPO_ with the name
|
||||||
|
# This changes everything in the content block of the template.
|
||||||
|
# It rewrites {{__REPO__.name}} into {{resque.name}}, for instance.
|
||||||
|
# You can prefix your environment variables and do other things as well.
|
||||||
|
|
||||||
|
echo -n "$1" | sed "s/__REPO__/${REPO}/"
|
||||||
|
|
||||||
|
echo "## Looped one time for repo: $REPO"
|
||||||
|
done
|
||||||
|
|
||||||
|
echo "# Finished EVERY_REPO"
|
||||||
|
}
|
||||||
|
|
||||||
|
REPOS=(resque hub rip)
|
||||||
|
|
||||||
|
declare -A resque hub rip
|
||||||
|
resque=([name]=Resque [url]=http://example.com/resque)
|
||||||
|
hub=([name]=Hub [url]=http://example.com/hub)
|
||||||
|
rip=([name]=Rip [url]=http://example.com/rip)
|
||||||
|
|
||||||
|
cat <<EOF | . ../mo
|
||||||
|
{{#EVERY_REPO}}
|
||||||
|
The repo is __REPO__
|
||||||
|
Name: {{__REPO__.name}}
|
||||||
|
URL: {{__REPO__.url}}
|
||||||
|
{{/EVERY_REPO}}
|
||||||
|
|
||||||
|
EOF
|
Loading…
Reference in New Issue
Block a user