diff --git a/README.md b/README.md index 75b14fc..a97956e 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,7 @@ ``` terminal | | A bash template (BaT) to ease argument parsing and management + | 1.2.0 | | Usage: | bash_template.sh -a alpha -b bravo [-c charlie] -d delta @@ -27,7 +28,7 @@ - `args` - Routines created to: - Scan command-line arguments for accuracy and completeness - - Parse a JSON file for program configuration details, such as the following JSON configuration file: + - Parse a JSON file for program configuration details, such as the following JSON configuration file (used in the [A-Bash-Template (BaT)](https://github.com/richbl/a-bash-template#a-bash-template) project): ``` json { @@ -80,11 +81,10 @@ Of course we are! Otherwise, what value does a BaT offer if it doesn't get used All of our bash scripts have been written to use this project. It's cut our development time, and made it easier to provide updates and added functionality without having to spend time reinventing the wheel every time. Check out all of our projects here on [Github](https://github.com/richbl). - ## This Project Uses Git Submodules This project is managed as a [Git submodule project(s)](https://git-scm.com/book/en/v2/Git-Tools-Submodules) to keep projects that use this library stable while this library is periodically updated. ## License -This project is distributed under the [MIT License](https://github.com/richbl/a-bash-template/blob/main/LICENSE) \ No newline at end of file +This project is distributed under the [MIT License](https://github.com/richbl/bash-lib/blob/main/LICENSE) \ No newline at end of file diff --git a/args b/args index 404ca4f..8130314 100644 --- a/args +++ b/args @@ -1,21 +1,22 @@ #!/usr/bin/env bash # ----------------------------------------------------------------------------- -# Copyright (C) Business Learning Incorporated (businesslearninginc.com) +# Copyright (c) 2025 Richard Bloch # -# 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. +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: # -# 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. +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. # # ----------------------------------------------------------------------------- # # Bash library (bash-lib) for command line argument loading/parsing/validating +# Version: 1.1.0 # # --- Constants and variables ----------------------------------------------- @@ -150,17 +151,27 @@ scan_for_args() { # ----------------------------------------------------------------------------- # check_for_args_completeness() verifies all required arguments are present # -function check_for_args_completeness() { +check_for_args_completeness() { - local count_errs=0 - local count_config_args=0 - count_config_args=$(get_config_args_length) - - for ((j = 0; j < count_config_args; j++)); do + _load_config + local err_count=0 + local arg_count + arg_count=$(get_config_args_length) - if [ -z "${ARG_VALUE[${j}]:-}" ] && [ "$(get_config_arg "$j" required)" == "true" ]; then - printf "%s\n" "Error: $(get_config_arg "$j" text_string) argument ($(get_config_arg "$j" short_form)|$(get_config_arg "$j" long_form)) missing." - ((count_errs++)) + for ((i = 0; i < arg_count; i++)); do + local is_required text_string short_form long_form + is_required=$(get_config_arg "$i" "required") + + if [[ "$is_required" == "true" ]]; then + text_string=$(get_config_arg "$i" "text_string") + + if [[ -z "${ARG_VALUE[${text_string}]:-}" ]]; then + short_form=$(get_config_arg "$i" "short_form") + long_form=$(get_config_arg "$i" "long_form") + printf "Error: argument '%s' (%s|%s) is missing.\n" \ + "$text_string" "$short_form" "$long_form" >&2 + ((err_count++)) + fi fi done diff --git a/general b/general index d60cabf..4833d6e 100644 --- a/general +++ b/general @@ -1,21 +1,22 @@ #!/usr/bin/env bash # ----------------------------------------------------------------------------- -# Copyright (C) Business Learning Incorporated (businesslearninginc.com) +# Copyright (c) 2025 Richard Bloch # -# 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. +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: # -# 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. +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. # # ----------------------------------------------------------------------------- # # Bash library (bash-lib) for general-purpose script processing +# Version: 1.1.0 # # ----------------------------------------------------------------------------- @@ -104,18 +105,6 @@ exist_directory() { } -# ----------------------------------------------------------------------------- -# function exist_directory() confirms directory existence -# -function exist_directory() { - - if [ ! -d "${1}" ]; then - printf "\n%s\n" "Error: directory ${1} not found." - quit 1 - fi - -} - # ----------------------------------------------------------------------------- # quit() exits program (with exit status passed in) #