@@ -138,23 +138,35 @@ function bashio::addon.changelog() {
138138}
139139
140140# ------------------------------------------------------------------------------
141- # Returns a JSON object with generic version information about addons.
141+ # Returns a JSON object with information about addons.
142142#
143143# Arguments:
144144# $1 Add-on slug (optional)
145- # $1 Cache key to store results in (optional)
146- # $2 jq Filter to apply on the result (optional)
145+ # (default/empty/'false' for all add-ons)
146+ # $2 Cache key to store filtered results in (optional)
147+ # (default/empty/'false' to cache only unfiltered results)
148+ # $3 jq Filter to apply on the result (optional)
149+ # (default/empty is '.addons[].slug' with no slug or '.slug' with slug)
150+ # ('false' for no filtering)
147151# ------------------------------------------------------------------------------
148152function bashio::addons() {
149153 local slug=${1:- false}
150- local cache_key=${2:- ' addons.list' }
151- local filter=${3:- ' .addons[].slug' }
154+ local cache_key=${2:- false}
155+ local filter=${3:- }
156+ if bashio::var.is_empty " ${filter} " ; then
157+ if bashio::var.false " ${slug} " ; then
158+ filter=' .addons[].slug'
159+ else
160+ filter=' .slug'
161+ fi
162+ fi
152163 local info
153164 local response
154165
155166 bashio::log.trace " ${FUNCNAME[0]} " " $@ "
156167
157- if bashio::cache.exists " ${cache_key} " ; then
168+ if ! bashio::var.false " ${cache_key} " \
169+ && bashio::cache.exists " ${cache_key} " ; then
158170 bashio::cache.get " ${cache_key} "
159171 return " ${__BASHIO_EXIT_OK} "
160172 fi
@@ -184,12 +196,14 @@ function bashio::addons() {
184196 fi
185197
186198 response=" ${info} "
187- if bashio::var.has_value " ${filter} " ; then
199+ if ! bashio::var.false " ${filter} " ; then
188200 response=$( bashio::jq " ${info} " " ${filter} " )
201+ if ! bashio::var.false " ${cache_key} " ; then
202+ bashio::cache.set " ${cache_key} " " ${response} "
203+ fi
189204 fi
190205
191- bashio::cache.set " ${cache_key} " " ${response} "
192- printf " %s" " ${response} "
206+ printf ' %s' " ${response} "
193207
194208 return " ${__BASHIO_EXIT_OK} "
195209}
0 commit comments