diff --git a/.vscode/shellscript.code-snippets b/.vscode/shellscript.code-snippets index 46a28ce..598cb24 100644 --- a/.vscode/shellscript.code-snippets +++ b/.vscode/shellscript.code-snippets @@ -25,8 +25,8 @@ "\t\t#\t\t\t\t\t\\$1 (Required):\t", "\t\t#\t\t\t\t\t\\$2 (Optional):\t", "\t\t# OUTS:", - "\t\t#\t\t\t\t\t\t\t 0: Success", - "\t\t#\t\t\t\t\t\t\t 1: Failure", + "\t\t#\t\t\t\t\t 0: Success", + "\t\t#\t\t\t\t\t 1: Failure", "\t\t#\t\t\t\t\tstdout: ", "\t\t# USAGE:", "\t\t#\t\t\t\t\t_nameOfFunc_ \"@\"" @@ -56,8 +56,8 @@ "\t\t#\t\t\t\t\t\\$1 (Required):\t", "\t\t#\t\t\t\t\t\\$2 (Optional):\t", "\t\t# OUTS:", - "\t\t#\t\t\t\t\t\t\t 0: Success", - "\t\t#\t\t\t\t\t\t\t 1: Failure", + "\t\t#\t\t\t\t\t 0: Success", + "\t\t#\t\t\t\t\t 1: Failure", "\t\t#\t\t\t\t\tstdout: ", "\t\t# USAGE:", "\t\t#\t\t\t\t\t_${1:name}_ \"@\"", diff --git a/README.md b/README.md index bfbc255..d0397ba 100644 --- a/README.md +++ b/README.md @@ -184,6 +184,7 @@ Functions for validating common use-cases - **`_isAlphaNum_`** Validate that a given variable contains only alpha-numeric characters - **`_isDir_`** Validate that a given input points to a valid directory - **`_isEmail_`** Validates that an input is a valid email address +- **`_isFQDN_`** Determines if a given input is a fully qualified domain name - **`_isFile_`** Validate that a given input points to a valid file - **`_isIPv4_`** Validates that an input is a valid IPv4 address - **`_isIPv6_`** Validates that an input is a valid IPv6 address diff --git a/test/alerts.bats b/test/alerts.bats index 74c8e68..4245ab0 100755 --- a/test/alerts.bats +++ b/test/alerts.bats @@ -100,7 +100,7 @@ teardown() { @test "_alert_: header" { run header "testing" - assert_output --regexp "\[ header\] testing" + assert_output --regexp "testing" } @test "_alert_: info" { diff --git a/utilities/alerts.bash b/utilities/alerts.bash index 6d4abf9..44c2dec 100644 --- a/utilities/alerts.bash +++ b/utilities/alerts.bash @@ -115,7 +115,11 @@ _alert_() { reset="" fi - printf "${_color}[%7s] %s${reset}\n" "${_alertType}" "${_message}" + if [[ ${_alertType} == header ]]; then + printf "${_color}%s${reset}\n" "${_message}" + else + printf "${_color}[%7s] %s${reset}\n" "${_alertType}" "${_message}" + fi } _writeToScreen_ diff --git a/utilities/checks.bash b/utilities/checks.bash index c99166b..2712836 100644 --- a/utilities/checks.bash +++ b/utilities/checks.bash @@ -120,6 +120,28 @@ _isEmail_() { [[ ${1} =~ ${_emailRegex} ]] && return 0 || return 1 } +_isFQDN_() { + # DESC: + # Determines if a given input is a fully qualified domain name + # ARGS: + # $1 (Required): String to validate + # OUTS: + # 0: Successfully validated as FQDN + # 1: Failed to validate as FQDN + # USAGE: + # _isFQDN_ "some.domain.com" + + [[ $# == 0 ]] && fatal "Missing required argument to ${FUNCNAME[0]}" + + local _input="${1}" + + if printf "${_input}" | grep -Pq '(?=^.{4,253}$)(^(?:[a-zA-Z0-9](?:(?:[a-zA-Z0-9\-]){0,61}[a-zA-Z0-9])?\.)+([a-zA-Z]{2,}|xn--[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])$)'; then + return 0 + else + return 1 + fi +} + _isInternetAvailable_() { # DESC: # Check if internet connection is available