From 197e637da14ade5632e61d500bf3b1ddda730bdf Mon Sep 17 00:00:00 2001 From: Price Hiller Date: Sat, 13 Nov 2021 21:16:57 -0600 Subject: [PATCH] Added help menu --- Misc/Templater.bash | 56 +++++++++++++++++++++++++++++++++++++++------ 1 file changed, 49 insertions(+), 7 deletions(-) diff --git a/Misc/Templater.bash b/Misc/Templater.bash index 489d4db..008743e 100755 --- a/Misc/Templater.bash +++ b/Misc/Templater.bash @@ -3,9 +3,15 @@ # "Import" our needed functions from our library LIBRARY_PATH="/usr/local/lib/Custom-Scripts" # shellcheck source=/usr/local/lib/ -source "${LIBRARY_PATH}/Logging-RGB.bash" || echo "Unable to source Logging-RGB.bash at ${LIBRARY_PATH}" +if ! source "${LIBRARY_PATH}/Logging-RGB.bash"; then + echo "Unable to source Logging-RGB.bash at ${LIBRARY_PATH}" + exit 1 +fi # shellcheck source=/usr/local/lib/ -source "${LIBRARY_PATH}/Trim.bash" || log "error" "Unable to source Trim.bash at ${LIBRARY_PATH}" +if ! source "${LIBRARY_PATH}/Trim.bash"; then + log "error" "Unable to source Trim.bash at ${LIBRARY_PATH}" + exit 1 +fi # Tmp file used because most distros have this dir exist in RAM, use PID of our process to write to TEMP_FILE="/tmp/$$" @@ -237,6 +243,18 @@ templater() { fi } +arg_required() { + echo_rgb "${1}" 255 183 0 +} + +arg_optional(){ + echo_rgb "${1}" 117 255 255 +} + +arg_description(){ + echo_rgb "${@}" 220 190 255 +} + usage() { # Print out usage instructions for the local script # @@ -250,13 +268,37 @@ usage() { # Yes # printf "Usage: %s\n" \ - "$(basename ${0}) -i \"this is some input\" -t \"this is some more example input\" - --input | -i + "$(basename ${0}) [OPTIONS] + $(arg_required "REQUIRED") + $(arg_optional "OPTIONAL") + + $(arg_required "--template-file") | $(arg_required "-t") + $(arg_description "A template file to parse and apply rules for + Example: - --input \"this is an example input\" - --test | -t + --template-file example.tmpl") + + $(arg_optional "--contents-dir") | $(arg_optional "-c") + $(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 + export CONTENTS_DIRECTORY=\`your contents directory\` + Example: - --test \"this is more example input\"" + --contents-dir ~/Desktop/contents") + + $(arg_optional "--output-to") | $(arg_optional "-o") + $(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: + --output-to myfile.out") + + $(arg_optional "--no-exit") | $(arg_optional "-n") + $(arg_description "Do not exit on any errors, continue executing + + Example: + --no-exit")" + } main() {