3 Commits
1.1.0 ... 2.0.2

Author SHA1 Message Date
Tyler Akins
4f615a0faf More fixes if variables are not set and strict mode is enabled 2017-11-13 10:43:32 -06:00
Tyler Akins
1e91e414cc Fix for when running in strict mode 2017-11-13 10:31:51 -06:00
Tyler Akins
ad98577c42 Changing how functions are called
Old way:

    functionName CONTENT argument1 argument2

New way:

    echo -n "$CONTENT" | functionName argument1 argument2

This follow the Unix style more closely.
2017-11-13 10:13:56 -06:00
7 changed files with 28 additions and 25 deletions

View File

@@ -3,6 +3,9 @@
cd "$(dirname "$0")" # Go to the script's directory cd "$(dirname "$0")" # Go to the script's directory
EVERY_REPO() { EVERY_REPO() {
# The block contents come in through standard input. Capture it here.
content=$(cat)
echo "# Starting EVERY_REPO" echo "# Starting EVERY_REPO"
# Get list of repos # Get list of repos
@@ -14,7 +17,7 @@ EVERY_REPO() {
# It rewrites {{__REPO__.name}} into {{resque.name}}, for instance. # It rewrites {{__REPO__.name}} into {{resque.name}}, for instance.
# You can prefix your environment variables and do other things as well. # You can prefix your environment variables and do other things as well.
echo -n "$1" | sed "s/__REPO__/${REPO}/" echo "$content" | sed "s/__REPO__/${REPO}/"
echo "## Looped one time for repo: $REPO" echo "## Looped one time for repo: $REPO"
done done

View File

@@ -2,13 +2,17 @@
cd "$(dirname "$0")"/.. cd "$(dirname "$0")"/..
date-string() { date; } date-string() {
wrapper() { echo -n "*** $1 ***"; } date
}
wrapper() {
echo -n "*** $(cat) ***"
}
export IP=127.0.0.1 export IP=127.0.0.1
export ALLOWED_HOSTS=( 192.168.0.1 192.168.0.2 192.168.0.3 ) 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 . ./mo # Keep in mind this script is executing in the parent directory
cat <<EOF | mo cat <<EOF | mo
# {{#wrapper}}OH SO IMPORTANT{{/wrapper}} # {{#wrapper}}OH SO IMPORTANT{{/wrapper}}
# This file automatically generated at {{date-string}} # This file automatically generated at {{date-string}}

17
mo
View File

@@ -141,15 +141,16 @@ mo() (
# #
# Returns nothing. # Returns nothing.
moCallFunction() { moCallFunction() {
local moCommand local moArgs
moArgs=()
# shellcheck disable=SC2031 # shellcheck disable=SC2031
if [[ -n "$MO_ALLOW_FUNCTION_ARGUMENTS" ]]; then if [[ -n "$MO_ALLOW_FUNCTION_ARGUMENTS" ]]; then
printf -v moCommand "%q %q %s" "$1" "$2" "$3" moArgs=$3
eval "$moCommand"
else
"$1" "$2"
fi fi
echo -n "$2" | eval "$1" "$moArgs"
} }
@@ -834,15 +835,15 @@ moShow() {
moSplit moNameParts "$1" "." moSplit moNameParts "$1" "."
if [[ -z "${moNameParts[1]}" ]]; then if [[ -z "${moNameParts[1]-}" ]]; then
if moIsArray "$1"; then if moIsArray "$1"; then
eval moJoin moJoined "," "\${$1[@]}" eval moJoin moJoined "," "\${$1[@]}"
echo -n "$moJoined" echo -n "$moJoined"
else else
# shellcheck disable=SC2031 # shellcheck disable=SC2031
if [[ -z "$MO_FAIL_ON_UNSET" ]] || moTestVarSet "$1"; then if moTestVarSet "$1"; then
echo -n "${!1}" echo -n "${!1}"
else elif [[ -n "${MO_FAIL_ON_UNSET-}" ]]; then
echo "Env variable not set: $1" >&2 echo "Env variable not set: $1" >&2
exit 1 exit 1
fi fi

View File

@@ -2,16 +2,12 @@ name=Willy
MO_ALLOW_FUNCTION_ARGUMENTS=true MO_ALLOW_FUNCTION_ARGUMENTS=true
pipeTo() { pipeTo() {
echo -n "$1" | "$2" cat | "$1"
} }
testArgs() { testArgs() {
printf "%d" "$#" printf "%d" "$#"
# Remove content. Note that when zero arguments are passed, this
# line does nothing and $1 will still be the content.
shift
# Display all arguments # Display all arguments
printf " %q" "$@" printf " %q" ${@+"$@"}
} }

View File

@@ -1,4 +1,4 @@
No args: 1 '' - done No args: 0 '' - done
One arg: 2 one - done One arg: 1 one - done
Getting name in a string: 2 The\ name\ is\ Willy - done Getting name in a string: 1 The\ name\ is\ Willy - done
Reverse this: edcba Reverse this: edcba

View File

@@ -1,5 +1,5 @@
name=Willy name=Willy
wrapped() { wrapped() {
# The final newline is eaten by mo # This eats the newline in the content
echo "<b>$1</b>" echo "<b>$(cat)</b>"
} }

View File

@@ -1,2 +1 @@
<b> Willy is awesome. <b> Willy is awesome.</b>... this is the last line.
</b>... this is the last line.