Add "mo" from "ssh://git@git.knownelement.com:29418/ExternalVendorCode/mo.git@master"
git-vendor-name: mo git-vendor-dir: vendor/git@git.knownelement.com/29418/ExternalVendorCode/mo git-vendor-repository: ssh://git@git.knownelement.com:29418/ExternalVendorCode/mo.git git-vendor-ref: master
This commit is contained in:
19
vendor/git@git.knownelement.com/29418/ExternalVendorCode/mo/demo/associative-arrays
vendored
Executable file
19
vendor/git@git.knownelement.com/29418/ExternalVendorCode/mo/demo/associative-arrays
vendored
Executable file
@@ -0,0 +1,19 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
cd "$(dirname "$0")" # Go to the script's directory
|
||||
|
||||
declare -A DATA
|
||||
export DATA=([one]=111 [two]=222)
|
||||
. ../mo
|
||||
|
||||
cat <<EOF | mo
|
||||
Accessing data directly:
|
||||
DATA: {{DATA}}
|
||||
One: {{DATA.one}}
|
||||
Two: {{DATA.two}}
|
||||
|
||||
Things in DATA:
|
||||
{{#DATA}}
|
||||
Item: {{.}}
|
||||
{{/DATA}}
|
||||
EOF
|
28
vendor/git@git.knownelement.com/29418/ExternalVendorCode/mo/demo/embedded-template
vendored
Executable file
28
vendor/git@git.knownelement.com/29418/ExternalVendorCode/mo/demo/embedded-template
vendored
Executable file
@@ -0,0 +1,28 @@
|
||||
#!/usr/bin/env bash
|
||||
#
|
||||
# This embeds a template in the script without using strange `cat` syntax.
|
||||
# shellcheck disable=SC1083 disable=SC1010 disable=SC1054 disable=SC1073 disable=SC1072 disable=SC1056 disable=SC1009
|
||||
|
||||
cd "$(dirname "$0")" # Go to the script's directory
|
||||
|
||||
export NAME="Tyler"
|
||||
export VEHICLE="Ford Explorer"
|
||||
export OVERDUE_LENGTH="2 months"
|
||||
export OPTIONS=(
|
||||
"Call a service representative at 1-800-000-0000 to discuss payment options"
|
||||
"Return the vehicle immediately and pay a fine of 1 million dollars"
|
||||
)
|
||||
. ../mo
|
||||
sed '0,/^# END/ d' "$(basename "$0")" | mo
|
||||
exit
|
||||
|
||||
# END
|
||||
Attention {{NAME}},
|
||||
|
||||
You need to pay for the {{VEHICLE}} you are leasing from us.
|
||||
It has been {{OVERDUE_LENGTH}} since your last payment.
|
||||
At this point you must do one of the following:
|
||||
|
||||
{{#OPTIONS}}
|
||||
* {{.}}
|
||||
{{/OPTIONS}}
|
3
vendor/git@git.knownelement.com/29418/ExternalVendorCode/mo/demo/fun-trip.mo
vendored
Normal file
3
vendor/git@git.knownelement.com/29418/ExternalVendorCode/mo/demo/fun-trip.mo
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
Hello, {{NAME}}
|
||||
|
||||
I hope your {{TIME_PERIOD}} was fun.
|
31
vendor/git@git.knownelement.com/29418/ExternalVendorCode/mo/demo/function-args
vendored
Executable file
31
vendor/git@git.knownelement.com/29418/ExternalVendorCode/mo/demo/function-args
vendored
Executable file
@@ -0,0 +1,31 @@
|
||||
#!/usr/bin/env bash
|
||||
#
|
||||
# This sources a simple script with the env. variables needed for the template.
|
||||
|
||||
cd "$(dirname "$0")" # Go to the script's directory
|
||||
source ../mo
|
||||
|
||||
export NAME="Alex"
|
||||
export ARRAY=( AAA BBB CCC )
|
||||
|
||||
# Include an external template
|
||||
INCLUDE() {
|
||||
# shellcheck disable=SC2031
|
||||
cat "${MO_FUNCTION_ARGS[0]}"
|
||||
}
|
||||
|
||||
# Print section title
|
||||
TITLE() {
|
||||
echo "+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+"
|
||||
# shellcheck disable=SC2031
|
||||
echo "${MO_FUNCTION_ARGS[0]}"
|
||||
echo "+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+"
|
||||
}
|
||||
|
||||
cat <<EOF | mo -u
|
||||
{{TITLE 'Part 1'}}
|
||||
{{INCLUDE 'function-args-part1'}}
|
||||
|
||||
{{TITLE 'Part 2'}}
|
||||
{{INCLUDE 'function-args-part2'}}
|
||||
EOF
|
1
vendor/git@git.knownelement.com/29418/ExternalVendorCode/mo/demo/function-args-part1
vendored
Normal file
1
vendor/git@git.knownelement.com/29418/ExternalVendorCode/mo/demo/function-args-part1
vendored
Normal file
@@ -0,0 +1 @@
|
||||
Hello, my name is {{NAME}}.
|
3
vendor/git@git.knownelement.com/29418/ExternalVendorCode/mo/demo/function-args-part2
vendored
Normal file
3
vendor/git@git.knownelement.com/29418/ExternalVendorCode/mo/demo/function-args-part2
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
{{#ARRAY}}
|
||||
* {{.}}
|
||||
{{/ARRAY}}
|
42
vendor/git@git.knownelement.com/29418/ExternalVendorCode/mo/demo/function-for-advanced-looping
vendored
Executable file
42
vendor/git@git.knownelement.com/29418/ExternalVendorCode/mo/demo/function-for-advanced-looping
vendored
Executable file
@@ -0,0 +1,42 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
cd "$(dirname "$0")" # Go to the script's directory
|
||||
|
||||
EVERY_REPO() {
|
||||
# The block contents come in through standard input. Capture it here.
|
||||
content=$(cat)
|
||||
|
||||
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 "$content" | 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)
|
||||
. ../mo
|
||||
cat <<EOF | mo
|
||||
{{#EVERY_REPO}}
|
||||
The repo is __REPO__
|
||||
Name: {{__REPO__.name}}
|
||||
URL: {{__REPO__.url}}
|
||||
{{/EVERY_REPO}}
|
||||
|
||||
EOF
|
39
vendor/git@git.knownelement.com/29418/ExternalVendorCode/mo/demo/function-for-building-json
vendored
Executable file
39
vendor/git@git.knownelement.com/29418/ExternalVendorCode/mo/demo/function-for-building-json
vendored
Executable file
@@ -0,0 +1,39 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
cd "$(dirname "$0")" # Go to the script's directory
|
||||
|
||||
# Detect if this is the first item and write a comma if it is.
|
||||
# Normally, I would track this using a variable, like so:
|
||||
#
|
||||
# COMMA_IF_NOT_FIRST_FLAG=false
|
||||
# COMMA_IF_NOT_FIRST() {
|
||||
# $COMMA_IF_NOT_FIRST || echo ","
|
||||
# COMMA_IF_NOT_FIRST_FLAG=true
|
||||
# }
|
||||
#
|
||||
# Since this function executes in a subshell, that approach will not work.
|
||||
# Instead, we peek inside mo and see what is being processed. If the variable
|
||||
# name in moParse() changes, this will need to get updated as well. An
|
||||
# alternate variable that is usable is context, but that is in moLoop() and is
|
||||
# two levels levels deep instead of just one.
|
||||
COMMA_IF_NOT_FIRST() {
|
||||
[[ "${moCurrent#*.}" != "0" ]] && echo ","
|
||||
}
|
||||
|
||||
# Create an array that will be embedded into the JSON. If you are manipulating
|
||||
# JSON, might I suggest you look at using jq? It's really good at processing
|
||||
# JSON.
|
||||
items=(
|
||||
'{"position":"one","url":"1"}'
|
||||
'{"position":"two","url":"2"}'
|
||||
'{"position":"three","url":"3"}'
|
||||
)
|
||||
. ../mo
|
||||
cat <<EOF | mo
|
||||
{
|
||||
{{#items}}
|
||||
{{COMMA_IF_NOT_FIRST}}
|
||||
{{.}}
|
||||
{{/items}}
|
||||
}
|
||||
EOF
|
50
vendor/git@git.knownelement.com/29418/ExternalVendorCode/mo/demo/function-for-foreach
vendored
Executable file
50
vendor/git@git.knownelement.com/29418/ExternalVendorCode/mo/demo/function-for-foreach
vendored
Executable file
@@ -0,0 +1,50 @@
|
||||
#!/usr/bin/env bash
|
||||
# Example for how #29 can get implemented.
|
||||
|
||||
cd "$(dirname "$0")" # Go to the script's directory
|
||||
|
||||
foreach() {
|
||||
# Trying to use unique names
|
||||
local foreachSourceName foreachIterator foreachEvalString foreachContent
|
||||
|
||||
foreachContent=$(cat)
|
||||
|
||||
local x
|
||||
x=("${@}")
|
||||
if [[ "$2" != "as" && "$2" != "in" ]]; then
|
||||
echo "Invalid foreach - bad format."
|
||||
elif [[ "$(declare -p "$1")" != "declare -"[aA]* ]]; then
|
||||
echo "$1 is not an array"
|
||||
else
|
||||
foreachSourceName="${1}[@]"
|
||||
|
||||
for foreachIterator in "${!foreachSourceName}"; do
|
||||
foreachEvalString=$(declare -p "$foreachIterator")
|
||||
foreachEvalString="declare -A $3=${foreachEvalString#*=}"
|
||||
eval "$foreachEvalString"
|
||||
echo "$foreachContent" | mo
|
||||
done
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
# The links are associative arrays
|
||||
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)
|
||||
|
||||
# This is a list of the link arrays
|
||||
links=(resque hub rip)
|
||||
|
||||
# Source mo in order to work with arrays
|
||||
. ../mo
|
||||
|
||||
# Process the template
|
||||
cat <<EOF | mo --allow-function-arguments
|
||||
Here are your links:
|
||||
{{#foreach 'links' 'as' 'link'}}
|
||||
* [{{link.name}}]({{link.url}})
|
||||
{{/foreach 'links' 'as' 'link'}}
|
||||
|
||||
EOF
|
28
vendor/git@git.knownelement.com/29418/ExternalVendorCode/mo/demo/important-file
vendored
Executable file
28
vendor/git@git.knownelement.com/29418/ExternalVendorCode/mo/demo/important-file
vendored
Executable file
@@ -0,0 +1,28 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
cd "$(dirname "$0")"/..
|
||||
|
||||
date-string() {
|
||||
date
|
||||
}
|
||||
wrapper() {
|
||||
echo -n "*** $(cat) ***"
|
||||
}
|
||||
|
||||
export IP=127.0.0.1
|
||||
export ALLOWED_HOSTS=( 192.168.0.1 192.168.0.2 192.168.0.3 )
|
||||
|
||||
. ./mo # Keep in mind this script is executing in the parent directory
|
||||
cat <<EOF | mo
|
||||
# {{#wrapper}}OH SO IMPORTANT{{/wrapper}}
|
||||
# This file automatically generated at {{date-string}}
|
||||
home_ip={{IP}}
|
||||
|
||||
# ALLOWED HOSTS
|
||||
{{#ALLOWED_HOSTS}}allowed_host={{.}}
|
||||
{{/ALLOWED_HOSTS}}{{^ALLOWED_HOSTS}}# No allowed hosts{{/ALLOWED_HOSTS}}
|
||||
|
||||
# DENIED HOSTS
|
||||
{{#DENIED_HOSTS}}denied_host={{.}}
|
||||
{{/DENIED_HOSTS}}{{^DENIED_HOSTS}}# No denied hosts{{/DENIED_HOSTS}}
|
||||
EOF
|
15
vendor/git@git.knownelement.com/29418/ExternalVendorCode/mo/demo/indented-partial
vendored
Executable file
15
vendor/git@git.knownelement.com/29418/ExternalVendorCode/mo/demo/indented-partial
vendored
Executable file
@@ -0,0 +1,15 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
export data=$'line 1\nline 2'
|
||||
|
||||
cat <<EOF | ../mo
|
||||
Here is a partial without an indent:
|
||||
|
||||
{{> partial}}
|
||||
|
||||
And here's the same partial with a 4-space indent:
|
||||
|
||||
{{> partial}}
|
||||
|
||||
:-)
|
||||
EOF
|
1
vendor/git@git.knownelement.com/29418/ExternalVendorCode/mo/demo/partial
vendored
Normal file
1
vendor/git@git.knownelement.com/29418/ExternalVendorCode/mo/demo/partial
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{{data}}
|
13
vendor/git@git.knownelement.com/29418/ExternalVendorCode/mo/demo/sourcing
vendored
Executable file
13
vendor/git@git.knownelement.com/29418/ExternalVendorCode/mo/demo/sourcing
vendored
Executable file
@@ -0,0 +1,13 @@
|
||||
#!/usr/bin/env bash
|
||||
#
|
||||
# This sources a simple script with the env. variables needed for the template.
|
||||
|
||||
cd "$(dirname "$0")" # Go to the script's directory
|
||||
|
||||
cat <<EOF | ../mo --source=sourcing.vars
|
||||
Hello, my name is {{NAME}}.
|
||||
And this is ARRAY's conntents:
|
||||
{{#ARRAY}}
|
||||
* {{.}}
|
||||
{{/ARRAY}}
|
||||
EOF
|
2
vendor/git@git.knownelement.com/29418/ExternalVendorCode/mo/demo/sourcing.vars
vendored
Normal file
2
vendor/git@git.knownelement.com/29418/ExternalVendorCode/mo/demo/sourcing.vars
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
export NAME="Alex"
|
||||
export ARRAY=( AAA BBB CCC )
|
10
vendor/git@git.knownelement.com/29418/ExternalVendorCode/mo/demo/using-arrays
vendored
Executable file
10
vendor/git@git.knownelement.com/29418/ExternalVendorCode/mo/demo/using-arrays
vendored
Executable file
@@ -0,0 +1,10 @@
|
||||
#!/usr/bin/env bash
|
||||
cd "$(dirname "$0")" # Go to the script's directory
|
||||
export ARRAY=( one two "three three three" four five )
|
||||
. ../mo
|
||||
cat << EOF | mo
|
||||
Here are the items in the array:
|
||||
{{#ARRAY}}
|
||||
* {{.}}
|
||||
{{/ARRAY}}
|
||||
EOF
|
7
vendor/git@git.knownelement.com/29418/ExternalVendorCode/mo/demo/using-strings
vendored
Executable file
7
vendor/git@git.knownelement.com/29418/ExternalVendorCode/mo/demo/using-strings
vendored
Executable file
@@ -0,0 +1,7 @@
|
||||
#!/usr/bin/env bash
|
||||
#
|
||||
# This example does not source `mo` and is intentionally restricted to
|
||||
# variables that are not arrays.
|
||||
cd "$(dirname "$0")" # Go to the script's directory
|
||||
export TEST="This is a test"
|
||||
echo "Your message: {{TEST}}" | ../mo
|
12
vendor/git@git.knownelement.com/29418/ExternalVendorCode/mo/demo/writing-out-braces
vendored
Executable file
12
vendor/git@git.knownelement.com/29418/ExternalVendorCode/mo/demo/writing-out-braces
vendored
Executable file
@@ -0,0 +1,12 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
cd "$(dirname "$0")" # Go to the script's directory
|
||||
|
||||
|
||||
export OPEN="{{"
|
||||
export CLOSE="}}"
|
||||
cat <<'EOF' | mo
|
||||
You can use environment variables to write output that has double braces.
|
||||
|
||||
{{OPEN}}sampleTag{{CLOSE}}
|
||||
EOF
|
Reference in New Issue
Block a user