added possibility to document template parameters
This commit is contained in:
20
template.sh
20
template.sh
@@ -2,11 +2,20 @@
|
|||||||
|
|
||||||
while test $# -gt 0; do
|
while test $# -gt 0; do
|
||||||
case "$1" in
|
case "$1" in
|
||||||
(-h|--help) cat <<EOF
|
(-h|--help) if test -e "${!#}"; then
|
||||||
|
cat <<EOF
|
||||||
|
$0 $(sed -n 's,^ *# *,,p' "${!#}" | tr '\n' ' ') ${!#}
|
||||||
|
EOF
|
||||||
|
else
|
||||||
|
cat <<EOF
|
||||||
$0 [OPTIONS] FILE
|
$0 [OPTIONS] FILE
|
||||||
|
|
||||||
OPTIONS
|
OPTIONS
|
||||||
|
|
||||||
|
-h, --help Show this help
|
||||||
|
|
||||||
|
-h, --help file Show usage of template file (if documented)
|
||||||
|
|
||||||
-v, --var name=value Set environment variable to be used in the template.
|
-v, --var name=value Set environment variable to be used in the template.
|
||||||
|
|
||||||
-p, --pwd name Generate a random password with the given name.
|
-p, --pwd name Generate a random password with the given name.
|
||||||
@@ -17,6 +26,9 @@ FILE
|
|||||||
and execute bash commands, e.g. you are allowed wo use the \$()
|
and execute bash commands, e.g. you are allowed wo use the \$()
|
||||||
expression.
|
expression.
|
||||||
|
|
||||||
|
Document the parameters that shall be used in comment lines, this
|
||||||
|
are lines thet start with # followed by -v or -p options.
|
||||||
|
|
||||||
DESCRIPTION
|
DESCRIPTION
|
||||||
|
|
||||||
Parse a template file and generate an instance for it, using the
|
Parse a template file and generate an instance for it, using the
|
||||||
@@ -27,6 +39,9 @@ EXAMPLE
|
|||||||
|
|
||||||
file wordpress.tpl
|
file wordpress.tpl
|
||||||
-----------------------------------------------------------------------------
|
-----------------------------------------------------------------------------
|
||||||
|
# -v NAME=
|
||||||
|
# -v PORT=
|
||||||
|
# -p PASSWORD
|
||||||
version: '3.3'
|
version: '3.3'
|
||||||
services:
|
services:
|
||||||
mysql:
|
mysql:
|
||||||
@@ -68,6 +83,7 @@ services:
|
|||||||
$0 -v NAME=my-site -v PORT=8006 -p PASSWORD wordpress.tpl > my-site.yaml
|
$0 -v NAME=my-site -v PORT=8006 -p PASSWORD wordpress.tpl > my-site.yaml
|
||||||
|
|
||||||
EOF
|
EOF
|
||||||
|
fi
|
||||||
exit;;
|
exit;;
|
||||||
(-v|--var) shift;
|
(-v|--var) shift;
|
||||||
if [[ $1 =~ ^[a-zA-Z][a-zA-Z0-9_]*= ]]; then
|
if [[ $1 =~ ^[a-zA-Z][a-zA-Z0-9_]*= ]]; then
|
||||||
@@ -107,6 +123,6 @@ if ! test -e "$file"; then
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
eval "cat <<EOFXXXX
|
eval "sed '/^ *#/d' <<EOFXXXX
|
||||||
$(<$file)
|
$(<$file)
|
||||||
EOFXXXX"
|
EOFXXXX"
|
||||||
|
Reference in New Issue
Block a user