add _isFQDN_ and change header style

This commit is contained in:
Nathaniel Landau
2021-10-23 23:51:24 -04:00
parent 21d6c9b985
commit a9e8029d9e
5 changed files with 33 additions and 6 deletions

View File

@@ -25,8 +25,8 @@
"\t\t#\t\t\t\t\t\\$1 (Required):\t", "\t\t#\t\t\t\t\t\\$1 (Required):\t",
"\t\t#\t\t\t\t\t\\$2 (Optional):\t", "\t\t#\t\t\t\t\t\\$2 (Optional):\t",
"\t\t# OUTS:", "\t\t# OUTS:",
"\t\t#\t\t\t\t\t\t\t 0: Success", "\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 1: Failure",
"\t\t#\t\t\t\t\tstdout: ", "\t\t#\t\t\t\t\tstdout: ",
"\t\t# USAGE:", "\t\t# USAGE:",
"\t\t#\t\t\t\t\t_nameOfFunc_ \"@\"" "\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\\$1 (Required):\t",
"\t\t#\t\t\t\t\t\\$2 (Optional):\t", "\t\t#\t\t\t\t\t\\$2 (Optional):\t",
"\t\t# OUTS:", "\t\t# OUTS:",
"\t\t#\t\t\t\t\t\t\t 0: Success", "\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 1: Failure",
"\t\t#\t\t\t\t\tstdout: ", "\t\t#\t\t\t\t\tstdout: ",
"\t\t# USAGE:", "\t\t# USAGE:",
"\t\t#\t\t\t\t\t_${1:name}_ \"@\"", "\t\t#\t\t\t\t\t_${1:name}_ \"@\"",

View File

@@ -184,6 +184,7 @@ Functions for validating common use-cases
- **`_isAlphaNum_`** Validate that a given variable contains only alpha-numeric characters - **`_isAlphaNum_`** Validate that a given variable contains only alpha-numeric characters
- **`_isDir_`** Validate that a given input points to a valid directory - **`_isDir_`** Validate that a given input points to a valid directory
- **`_isEmail_`** Validates that an input is a valid email address - **`_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 - **`_isFile_`** Validate that a given input points to a valid file
- **`_isIPv4_`** Validates that an input is a valid IPv4 address - **`_isIPv4_`** Validates that an input is a valid IPv4 address
- **`_isIPv6_`** Validates that an input is a valid IPv6 address - **`_isIPv6_`** Validates that an input is a valid IPv6 address

View File

@@ -100,7 +100,7 @@ teardown() {
@test "_alert_: header" { @test "_alert_: header" {
run header "testing" run header "testing"
assert_output --regexp "\[ header\] testing" assert_output --regexp "testing"
} }
@test "_alert_: info" { @test "_alert_: info" {

View File

@@ -115,7 +115,11 @@ _alert_() {
reset="" reset=""
fi 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_ _writeToScreen_

View File

@@ -120,6 +120,28 @@ _isEmail_() {
[[ ${1} =~ ${_emailRegex} ]] && return 0 || return 1 [[ ${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_() { _isInternetAvailable_() {
# DESC: # DESC:
# Check if internet connection is available # Check if internet connection is available