refactor: improve template handler on shell expansions

This commit is contained in:
Price Hiller 2023-09-15 17:12:24 -05:00
parent 3594d15c5c
commit 1e4740a08f
No known key found for this signature in database

View File

@ -52,14 +52,6 @@ log() {
# Yes # Yes
# #
# Set debug status depending if a global debug variable has been set to either 1 or 0
local debug
if [ ${DEBUG} ]; then
debug=${DEBUG}
else
debug=0
fi
local FORMAT local FORMAT
FORMAT="[$(echo_rgb "$(date +%Y-%m-%dT%H:%M:%S)" 180 140 255)]" FORMAT="[$(echo_rgb "$(date +%Y-%m-%dT%H:%M:%S)" 180 140 255)]"
@ -166,7 +158,7 @@ _write_to_buffer() {
var_handler() { var_handler() {
local variable="${1}" local variable="${1}"
local leading_spaces="${2}" local leading_spaces="${2}"
while IFS="\n" read -r line; do while IFS=$'\n' read -r line; do
write_content "${line}" "${leading_spaces}" write_content "${line}" "${leading_spaces}"
done <<<"${variable}" done <<<"${variable}"
} }
@ -174,7 +166,7 @@ var_handler() {
eval_handler() { eval_handler() {
local eval_statement="${1}" local eval_statement="${1}"
local leading_spaces="${2}" local leading_spaces="${2}"
while IFS="\n" read -r line; do while IFS=$'\n' read -r line; do
write_content "${line}" "${leading_spaces}" write_content "${line}" "${leading_spaces}"
done <<<"$(eval "${eval_statement}")" done <<<"$(eval "${eval_statement}")"
} }
@ -215,7 +207,7 @@ file_handler() {
return 1 return 1
fi fi
while IFS="\n" read -r line; do while IFS=$'\n' read -r line; do
write_content "${line}" "${leading_spaces}" write_content "${line}" "${leading_spaces}"
done <"${file}" done <"${file}"
} }
@ -330,7 +322,7 @@ read_template() {
line_num=1 line_num=1
read_file="${1}" read_file="${1}"
log "info" "Parsing template file \"${read_file}\"" log "info" "Parsing template file \"${read_file}\""
while IFS="\n" read -r line; do while IFS=$'\n' read -r line; do
# Check for non zero status code # Check for non zero status code
if ! parse_template_line "${line}"; then if ! parse_template_line "${line}"; then
log "error" "Invalid template passed from \"${read_file}\", check line ${line_num}" log "error" "Invalid template passed from \"${read_file}\", check line ${line_num}"
@ -389,7 +381,7 @@ usage() {
# Yes # Yes
# #
printf "Usage: %s\n" \ printf "Usage: %s\n" \
"$(basename ${0}) [OPTIONS] "$(basename "${0}") [OPTIONS]
$(arg_required "REQUIRED") $(arg_required "REQUIRED")
$(arg_optional "OPTIONAL") $(arg_optional "OPTIONAL")