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
|
||||
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
|
||||
|
||||
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.
|
||||
|
||||
-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 \$()
|
||||
expression.
|
||||
|
||||
Document the parameters that shall be used in comment lines, this
|
||||
are lines thet start with # followed by -v or -p options.
|
||||
|
||||
DESCRIPTION
|
||||
|
||||
Parse a template file and generate an instance for it, using the
|
||||
@@ -27,6 +39,9 @@ EXAMPLE
|
||||
|
||||
file wordpress.tpl
|
||||
-----------------------------------------------------------------------------
|
||||
# -v NAME=
|
||||
# -v PORT=
|
||||
# -p PASSWORD
|
||||
version: '3.3'
|
||||
services:
|
||||
mysql:
|
||||
@@ -68,6 +83,7 @@ services:
|
||||
$0 -v NAME=my-site -v PORT=8006 -p PASSWORD wordpress.tpl > my-site.yaml
|
||||
|
||||
EOF
|
||||
fi
|
||||
exit;;
|
||||
(-v|--var) shift;
|
||||
if [[ $1 =~ ^[a-zA-Z][a-zA-Z0-9_]*= ]]; then
|
||||
@@ -107,6 +123,6 @@ if ! test -e "$file"; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
eval "cat <<EOFXXXX
|
||||
eval "sed '/^ *#/d' <<EOFXXXX
|
||||
$(<$file)
|
||||
EOFXXXX"
|
||||
|
Reference in New Issue
Block a user