Adds functions to check if config/var is equal to a value

This commit is contained in:
Franck Nijhof 2019-03-15 12:15:08 +01:00
parent 46aa0b1784
commit 7c7386b502
No known key found for this signature in database
GPG key ID: D62583BA8AB11CA3
2 changed files with 28 additions and 3 deletions

View file

@ -120,6 +120,29 @@ function bashio::config.is_empty() {
return "${__BASHIO_EXIT_NOK}" return "${__BASHIO_EXIT_NOK}"
} }
# ------------------------------------------------------------------------------
# Checks if a configuration option equals a value.
#
# Arguments:
# $1 Key of the config option
# $2 Checks if the configuration option matches
# ------------------------------------------------------------------------------
function bashio::config.equals() {
local key=${1}
local equals=${2}
local value
bashio::log.trace "${FUNCNAME[0]}:" "$@"
value=$(bashio::config "${key}")
echo ":P ${value}"
if ! bashio::var.equals "${value}" "${equals}"; then
return "${__BASHIO_EXIT_NOK}"
fi
return "${__BASHIO_EXIT_OK}"
}
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Checks if a configuration option is true. # Checks if a configuration option is true.
# #
@ -386,7 +409,7 @@ function bashio::config.require.password() {
bashio::log.fatal bashio::log.fatal
bashio::log.fatal "Setting a password is required!" bashio::log.fatal "Setting a password is required!"
bashio::log.fatal bashio::log.fatal
bashio::log.fatal "Please password in the '${key}' option." bashio::log.fatal "Please set a password in the '${key}' option."
bashio::log.fatal bashio::log.fatal
bashio::log.fatal "If unsure, check the add-on manual for more information." bashio::log.fatal "If unsure, check the add-on manual for more information."
bashio::log.fatal bashio::log.fatal

View file

@ -98,13 +98,15 @@ function bashio::var.is_empty() {
# #
# Arguments: # Arguments:
# $1 Value # $1 Value
# $2 Equals value
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
function bashio::var.is_empty() { function bashio::var.equals() {
local value=${1} local value=${1}
local equals=${2}
bashio::log.trace "${FUNCNAME[0]}:" "$@" bashio::log.trace "${FUNCNAME[0]}:" "$@"
if [[ -z "${value}" ]]; then if [[ "${value}" = "${equals}" ]]; then
return "${__BASHIO_EXIT_OK}" return "${__BASHIO_EXIT_OK}"
fi fi