diff --git a/README.md b/README.md index 00bb48e..b1d58c3 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,6 @@ >> | | A bash template (BaT) to ease argument parsing and management - | 0.2.0 | | Usage: | bash_template.sh -a alpha -b bravo [-c charlie] -d delta diff --git a/args b/args index aad0d1b..710cbcb 100644 --- a/args +++ b/args @@ -11,51 +11,51 @@ PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin # # This program is distributed in the hope that it will be useful, but WITHOUT # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS -# FOR A PARTICULAR PURPOSE. See the GNU General Public License at +# FOR A PARTICULAR PURPOSE. See the GNU General Public License at # for more details. # # ----------------------------------------------------------------------------- # # bash library for command line argument loading/parsing/validating # - -readonly ARGS_FILE="data/config.json" +EXEC_DIR="$(dirname "$(readlink -f "$0")")" +readonly ARGS_FILE="${EXEC_DIR}/data/config.json" # ----------------------------------------------------------------------------- -# query data/config.json, returning the details object +# get_config_details(), using external jq command, queries data/config.json, +# returning the details object # -function get_config_details { - printf "%s" "$(jq -r '.details.'"$1"'' < "${ARGS_FILE}")" +function get_config_details() { + printf "%s" "$(jq -r '.details.'"$1"'' <"${ARGS_FILE}")" } # ----------------------------------------------------------------------------- -# query data/config.json, returning the arguments object +# get_config_arg(), using external jq command, queries data/config.json, +# returning the arguments object # -function get_config_arg { - printf "%s" "$(jq -r '.arguments['"$1"'].'"$2"'' < "${ARGS_FILE}")" +function get_config_arg() { + printf "%s" "$(jq -r '.arguments['"$1"'].'"$2"'' <"${ARGS_FILE}")" } # ----------------------------------------------------------------------------- -# query data/config.json, returning the count of arguments +# get_config_args_length(), using external jq command, queries +# data/config.json, returning the count of arguments # -function get_config_args_length { - printf "%s" "$(jq -r '.arguments|length' < "${ARGS_FILE}")" +function get_config_args_length() { + printf "%s" "$(jq -r '.arguments|length' <"${ARGS_FILE}")" } # ----------------------------------------------------------------------------- -# return argument value from argument key passed into +# get_config_arg_value() returns argument value text from argument keys # -function get_config_arg_value { +function get_config_arg_value() { local count_config_args=0 count_config_args=$(get_config_args_length) - for ((j=0;j for more details. # # ----------------------------------------------------------------------------- @@ -20,9 +20,10 @@ PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin # # ----------------------------------------------------------------------------- -# check program dependencies +# check_program_dependencies() checks external program dependencies passed in +# through $0 # -function check_program_dependencies { +function check_program_dependencies() { local -a deps=("$@") @@ -38,9 +39,9 @@ function check_program_dependencies { } # ----------------------------------------------------------------------------- -# check file dependencies +# check_file_dependencies() checks file dependencies passed in through $0 # -function check_file_dependencies { +function check_file_dependencies() { local -a deps=("$@") @@ -56,9 +57,10 @@ function check_file_dependencies { } # ----------------------------------------------------------------------------- -# display script banner +# display_banner() builds and displays a custom-sized script banner using +# configuration details managed through the args library # -function display_banner { +function display_banner() { printf "\n" printf "%s\n" " |" @@ -75,13 +77,13 @@ function display_banner { # determine maximum column width for setting output columns # - for ((j=0;j max_col)) && max_col=${#arg_len} - ((j == count_args-1 )) && ((max_col+=6)) + ((j == count_args - 1)) && ((max_col += 6)) done - for ((j=0;j