hack/lib/util.sh: mark variables to be used in a sourcing context.

"Decorate" the variables with a no-op function to prevent shellcheck
from complaining that they are not being used. This method provides
visibility to which variables are supposed to be used in a sourcing
script compared to just disabling the warning.
pull/564/head
Ismo Puustinen 2019-02-19 16:01:37 +02:00
parent 24b5c67723
commit edd806330a
1 changed files with 20 additions and 0 deletions

View File

@ -14,6 +14,13 @@
# See the License for the specific language governing permissions and
# limitations under the License.
function kube::util::sourced_variable {
# Call this function to tell shellcheck that a variable is supposed to
# be used from other calling context. This helps quiet an "unused
# variable" warning from shellcheck and also document your code.
true
}
kube::util::sortable_date() {
date "+%Y%m%d-%H%M%S"
}
@ -201,6 +208,10 @@ kube::util::gen-docs() {
genyaml=$(kube::util::find-binary "genyaml")
genfeddocs=$(kube::util::find-binary "genfeddocs")
# TODO: If ${genfeddocs} is not used from anywhere (it isn't used at
# least from k/k tree), remove it completely.
kube::util::sourced_variable "${genfeddocs}"
mkdir -p "${dest}/docs/user-guide/kubectl/"
"${gendocs}" "${dest}/docs/user-guide/kubectl/"
mkdir -p "${dest}/docs/admin/"
@ -777,6 +788,7 @@ function kube::util::ensure-gnu-sed {
kube::log::error "Failed to find GNU sed as sed or gsed. If you are on Mac: brew install gnu-sed." >&2
return 1
fi
kube::util::sourced_variable "${SED}"
}
# kube::util::check-file-in-alphabetical-order <file>
@ -814,6 +826,14 @@ if [[ -z "${color_start-}" ]]; then
declare -r color_blue="${color_start}1;34m"
declare -r color_cyan="${color_start}1;36m"
declare -r color_norm="${color_start}0m"
kube::util::sourced_variable "${color_start}"
kube::util::sourced_variable "${color_red}"
kube::util::sourced_variable "${color_yellow}"
kube::util::sourced_variable "${color_green}"
kube::util::sourced_variable "${color_blue}"
kube::util::sourced_variable "${color_cyan}"
kube::util::sourced_variable "${color_norm}"
fi
# ex: ts=2 sw=2 et filetype=sh