diff --git a/README.md b/README.md
index 18faee1..9ea36a5 100644
--- a/README.md
+++ b/README.md
@@ -4,5 +4,28 @@
**Bash-Lib** is a library of common [bash](https://en.wikipedia.org/wiki/Bash_%28Unix_shell%29) routines used in projects based on the [a-bash-template (BaT)](https://github.com/richbl/a-bash-template) project. This library is broken into two files:
- - `General`: Routines created to check program and file dependencies, banner display, *etc*.
- - `Args`: Routines created to manage command-line argument parsing
+- `general`: Routines created to:
+ - Check program dependencies
+ - Check file dependencies
+ - Format and display a program banner, e.g.,
+>>
+ |
+ | 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
+ |
+ | -a, --alpha alpha (something descriptive)
+ | -b, --bravo bravo (something descriptive)
+ | -c, --charlie charlie (this is optional)
+ | -d, --delta delta (something descriptive)
+ |
+
+- `args`: Routines created to:
+ - Parse a JSON file for program configuration details
+ - Scan command-line arguments for accuracy and completeness
+
+For details on how the various routines of this library project are used, see the [A-Bash-Template (BaT)](https://github.com/richbl/a-bash-template#a-bash-template) project.
+
+> Note that this project is managed as a Git [submodule](https://git-scm.com/book/en/v2/Git-Tools-Submodules) project specifically to keep projects that use this library up-to-date without manual intervention.
diff --git a/args b/args
index d1bc73d..aad0d1b 100644
--- a/args
+++ b/args
@@ -4,26 +4,22 @@ PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
# -----------------------------------------------------------------------------
# Copyright (C) Business Learning Incorporated (businesslearninginc.com)
#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
+# This program is free software: you can redistribute it and/or modify it under
+# the terms of the GNU General Public License as published by the Free Software
+# Foundation, either version 3 of the License, or (at your option) any later
+# version.
+#
+# 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 more details.
#
-# 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
-# more details.
# -----------------------------------------------------------------------------
#
# bash library for command line argument loading/parsing/validating
#
-EXEC_DIR="$(dirname "$0")"
-# shellcheck source=bash-lib/general
-source "${EXEC_DIR}/bash-lib/general"
-
-ARGS_FILE="${EXEC_DIR}/data/config.json"
+readonly ARGS_FILE="data/config.json"
# -----------------------------------------------------------------------------
# query data/config.json, returning the details object
@@ -40,7 +36,7 @@ function get_config_arg {
}
# -----------------------------------------------------------------------------
-# query data/config.json, returning the arguments object length
+# query data/config.json, returning the count of arguments
#
function get_config_args_length {
printf "%s" "$(jq -r '.arguments|length' < "${ARGS_FILE}")"
@@ -51,20 +47,18 @@ function get_config_args_length {
#
function get_config_arg_value {
- local COUNT_ARGS=0
- COUNT_ARGS=$(get_config_args_length)
+ local count_config_args=0
+ count_config_args=$(get_config_args_length)
- for ((j=0;j for more details.
#
-# 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
-# more details.
# -----------------------------------------------------------------------------
#
# bash library for general-purpose script processing
@@ -24,11 +24,11 @@ PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
#
function check_program_dependencies {
- local -a DEPS=("$@")
+ local -a deps=("$@")
- for i in "${DEPS[@]}"; do
+ for i in "${deps[@]}"; do
- if ! type "$i" &>/dev/null; then
+ if ! command -v "$i" &>/dev/null; then
printf "\n%s\n" "Error: program $i not installed."
quit 1
fi
@@ -42,9 +42,9 @@ function check_program_dependencies {
#
function check_file_dependencies {
- local -a DEPS=("$@")
+ local -a deps=("$@")
- for i in "${DEPS[@]}"; do
+ for i in "${deps[@]}"; do
if [ ! -f "$i" ]; then
printf "\n%s\n" "Error: file $i not found."
@@ -69,20 +69,20 @@ function display_banner {
printf "%s\n" " | $(get_config_details syntax)"
printf "%s\n" " |"
- local MAX_COL=0
- local COUNT_ARGS=0
- COUNT_ARGS=$(get_config_args_length)
+ local max_col=0
+ local count_args=0
+ count_args=$(get_config_args_length)
# 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))
+ for ((j=0;j max_col)) && max_col=${#arg_len}
+ ((j == count_args-1 )) && ((max_col+=6))
done
- for ((j=0;j