refactor: improve templater formatting

This commit is contained in:
Price Hiller 2023-09-15 17:21:43 -05:00
parent 1e4740a08f
commit 7e66668f98
No known key found for this signature in database

View File

@ -114,7 +114,7 @@ TEMP_FILE="$(mktemp)"
# Set the Contents directory to the env variable, script set, or to their .contents file in the user home # Set the Contents directory to the env variable, script set, or to their .contents file in the user home
CONTENTS_DIRECTORY="${CONTENTS_DIRECTORY:=\ CONTENTS_DIRECTORY="${CONTENTS_DIRECTORY:=\
$(mkdir -p "${HOME}/.contents" && echo "${HOME}/.contents")}" $(mkdir -p "${HOME}/.contents" && echo "${HOME}/.contents")}"
EXIT_ON_ERROR=0 EXIT_ON_ERROR=0
@ -380,37 +380,38 @@ usage() {
# POSIX Compliant: # POSIX Compliant:
# Yes # Yes
# #
printf "Usage: %s\n" \ cat <<EOF
"$(basename "${0}") [OPTIONS] Usage: $(basename ${0}) [OPTIONS]
$(arg_required "REQUIRED") $(arg_required "REQUIRED")
$(arg_optional "OPTIONAL") $(arg_optional "OPTIONAL")
$(arg_required "--template-file") <templateFile: string> | $(arg_required "-t") <templateFile: string> $(arg_required "--template-file") <templateFile: string> | $(arg_required "-t") <templateFile: string>
$(arg_description "A template file to parse and apply rules for $(arg_description "A template file to parse and apply rules for
Example: Example:
--template-file example.tmpl") --template-file example.tmpl")
$(arg_optional "--contents-dir") <contentsDirectory: string> | $(arg_optional "-c") <contentsDirectory: string> $(arg_optional "--contents-dir") <contentsDirectory: string> | $(arg_optional "-c") <contentsDirectory: string>
$(arg_description "The files that contain contents read by the templates. $(arg_description "The files that contain contents read by the templates.
By default this is set to ~/.contents/ if unset, to set via variable you can either use this argument or pass By default this is set to ~/.contents/ if unset, to set via variable you can either use this argument or pass
export CONTENTS_DIRECTORY=\`your contents directory\` export CONTENTS_DIRECTORY=\`your contents directory\`
Example: Example:
--contents-dir ~/Desktop/contents") --contents-dir ~/Desktop/contents")
$(arg_optional "--output-to") <outputFile: string> | $(arg_optional "-o") <outputFile: string> $(arg_optional "--output-to") <outputFile: string> | $(arg_optional "-o") <outputFile: string>
$(arg_description "The file to output the applied template to, this can be set within a template, but can be overriden with this option $(arg_description "The file to output the applied template to, this can be set within a template, but can be overriden with this option
Example: Example:
--output-to myfile.out") --output-to myfile.out")
$(arg_optional "--no-exit") | $(arg_optional "-n") $(arg_optional "--no-exit") | $(arg_optional "-n")
$(arg_description "Do not exit on any errors, continue executing $(arg_description "Do not exit on any errors, continue executing
Example: Example:
--no-exit")" --no-exit")
EOF
} }
@ -474,7 +475,7 @@ main() {
shift shift
done done
[[ -z "${template_file}" ]] && [[ -z "${template_file}" ]] &&
log "error" "No template file provided, exiting" && log "error" "No template file provided, exiting! Check \`-h\` for help." &&
exit 1 exit 1
templater "${template_file}" templater "${template_file}"
} }