diff --git a/README.md b/README.md index bf79e80..74fdfe3 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,7 @@ Detailed documentation is available at - [Installation](#installation) - [Method 1 - Git Submodules](#method-1---git-submodules) - [Method 2 - Git Clone](#method-2---git-clone) + - [Method 3 - Direct Download](#method-3---direct-download) - [Usage](#usage) - [Array](#array) - [array::contains()](#arraycontains) @@ -123,6 +124,7 @@ Detailed documentation is available at - [variable::is_bool()](#variableis_bool) - [variable::is_true()](#variableis_true) - [variable::is_false()](#variableis_false) + - [variable::is_empty_or_null()](#variableis_empty_or_null) - [Inspired By](#inspired-by) - [License](#license) @@ -1843,10 +1845,6 @@ Prompt yes or no question to the user. - **1**: If user responds with no. - **2**: Function missing arguments. -#### Output on stdout - -- question to be prompted to the user. - #### Example ```bash @@ -1871,7 +1869,7 @@ Prompt question to the user. #### Output on stdout -- question to be prompted to the user. +- User entered answer to the question. #### Example @@ -2450,6 +2448,28 @@ variable::is_false "false" 0 ``` +### variable::is_empty_or_null() + +Check if given variable is empty or null. + +#### Arguments + +- **$1** (mixed): Value of variable to check. + +#### Exit codes + +- **0**: If input is empty or null. +- **1**: If input is not empty. + +#### Example + +```bash +test='' +variable::is_empty_or_null $test +#Output +0 +``` + ## Inspired By diff --git a/bin/generate_readme.sh b/bin/generate_readme.sh index 972e997..5f8138d 100755 --- a/bin/generate_readme.sh +++ b/bin/generate_readme.sh @@ -12,6 +12,8 @@ Options:\n -s | --sh-dir - path to the bash script source folder to generate shdocs.\n -l | --toc-level - Minimum level of header to print in Table of Contents.\n -d | --toc-depth - Maximum depth of tree to print in Table of Contents.\n + -w | --webdoc - Flag to indicate generation of webdoc.\n + -p | --dest-dir - Path in which wedoc files must be generated.\n -h | --help - Display usage instructions.\n" "${0##*/}" exit 0 } diff --git a/src/interaction.sh b/src/interaction.sh index 53cf180..910b60e 100644 --- a/src/interaction.sh +++ b/src/interaction.sh @@ -16,8 +16,6 @@ # @exitcode 0 If user responds with yes. # @exitcode 1 If user responds with no. # @exitcode 2 Function missing arguments. -# -# @stdout question to be prompted to the user. interaction::prompt_yes_no() { [[ $# = 0 ]] && printf "%s: Missing arguments\n" "${FUNCNAME[0]}" && return 2 declare def_arg response @@ -71,7 +69,7 @@ interaction::prompt_yes_no() { # @exitcode 0 If user responds with answer. # @exitcode 2 Function missing arguments. # -# @stdout question to be prompted to the user. +# @stdout User entered answer to the question. interaction::prompt_response() { [[ $# = 0 ]] && printf "%s: Missing arguments\n" "${FUNCNAME[0]}" && return 2 diff --git a/src/variable.sh b/src/variable.sh index 230553f..60b7eeb 100644 --- a/src/variable.sh +++ b/src/variable.sh @@ -126,3 +126,19 @@ variable::is_true() { variable::is_false() { [[ "${1}" = false || "${1}" -eq 1 ]] && return 0 || return 1 } + +# @description Check if given variable is empty or null. +# +# @example +# test='' +# variable::is_empty_or_null $test +# #Output +# 0 +# +# @arg $1 mixed Value of variable to check. +# +# @exitcode 0 If input is empty or null. +# @exitcode 1 If input is not empty. +variable::is_empty_or_null() { + [[ -z "${1}" || "${1}" = "null" ]] && return 0 || return 1 +}