From 7c7386b502379893b51d2f5c701ef2924af2bde5 Mon Sep 17 00:00:00 2001 From: Franck Nijhof Date: Fri, 15 Mar 2019 12:15:08 +0100 Subject: [PATCH] :sparkles: Adds functions to check if config/var is equal to a value --- lib/config.sh | 25 ++++++++++++++++++++++++- lib/var.sh | 6 ++++-- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/lib/config.sh b/lib/config.sh index 7268fb4..d48df3f 100644 --- a/lib/config.sh +++ b/lib/config.sh @@ -120,6 +120,29 @@ function bashio::config.is_empty() { 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. # @@ -386,7 +409,7 @@ function bashio::config.require.password() { bashio::log.fatal bashio::log.fatal "Setting a password is required!" 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 "If unsure, check the add-on manual for more information." bashio::log.fatal diff --git a/lib/var.sh b/lib/var.sh index 9ce1542..0fa55cd 100644 --- a/lib/var.sh +++ b/lib/var.sh @@ -98,13 +98,15 @@ function bashio::var.is_empty() { # # Arguments: # $1 Value +# $2 Equals value # ------------------------------------------------------------------------------ -function bashio::var.is_empty() { +function bashio::var.equals() { local value=${1} + local equals=${2} bashio::log.trace "${FUNCNAME[0]}:" "$@" - if [[ -z "${value}" ]]; then + if [[ "${value}" = "${equals}" ]]; then return "${__BASHIO_EXIT_OK}" fi