diff --git a/utils.sh b/utils.sh index d7eeb22a5dfc1ee4e6619a45ce7ca63222aa32e3..dd62a9b3c71d8dfadff96834d5a013872ddefb7b 100755 --- a/utils.sh +++ b/utils.sh @@ -4,6 +4,8 @@ # # Intended to hold very common functionality (that's surprisingly not built into bash) such as string upper/lower, # and checking current user value, and prompts of yes/no user input. + # + # Version 1.0. ## @@ -28,6 +30,7 @@ declare -A kwargs=() global_args=() global_flags=() declare -A global_kwargs=() +help_flags=false # Function Return Variables. return_value="" @@ -359,6 +362,8 @@ function to_lower () { #endregion Text Manipulation Functions +#region Other Functions + ### # Handles passed values. # Splits into "args", "kwargs", and "flags": @@ -369,6 +374,10 @@ function to_lower () { # * Note that the associated value must come immediately after the key. # * Ex: "--type false", "--dir ./test", and "--name Bob". # * Args are any other values that don't match above formats. + # + # Note that "-h" and "--help" are handled separately, and considered to both be "help flags". + # If either one is provided, then a "help_flags" global variable is set to true. + # The expectation is that some kind of "display help" function will run instead of normal script functionality. ## handle_args_kwargs () { local handle_kwarg=false @@ -395,10 +404,14 @@ handle_args_kwargs () { for arg in ${@} do # Check arg type, based on substring match. - if [[ "${arg}" == "--"* && "${arg}" != "---"* ]] + if [[ "${arg}" == "-h" || "${arg}" == "--help" ]] then - # Handle for kwargs. + # Special handling for help flags. + help_flags=true + # Handle for kwargs. + elif [[ "${arg}" == "--"* && "${arg}" != "---"* ]] + then # Check for kwarg handling bool. if [[ ${handle_kwarg} == true ]] then @@ -411,10 +424,9 @@ handle_args_kwargs () { handle_kwarg=true fi + # Handle for flags. elif [[ "${arg}" == "-"* && "${arg}" != "--"* ]] then - # Handle for flags. - # Check for kwarg handling bool. if [[ ${handle_kwarg} == true ]] then @@ -432,9 +444,8 @@ handle_args_kwargs () { fi fi + # Handle for args. else - # Handle for args. - # Check for kwarg handling bool. if [[ ${handle_kwarg} == true ]] then @@ -482,6 +493,8 @@ function display_text_colors () { echo "" } +#endregion Other Functions + # Functions to call on script import. normalize_terminal