# HG changeset patch # User Franz Glasner # Date 1725028924 -7200 # Node ID fb362bcab7226eddc8ed2f697b703a9bc0337ede # Parent d10aad19eba351e79af711bea6e28034626b324b Implement "checkyesno()" and "checkyes()" in the common shell subroutines diff -r d10aad19eba3 -r fb362bcab722 share/local-bsdtools/common.subr --- a/share/local-bsdtools/common.subr Fri Aug 30 15:51:26 2024 +0200 +++ b/share/local-bsdtools/common.subr Fri Aug 30 16:42:04 2024 +0200 @@ -55,6 +55,66 @@ #: +#: Test $1 variable, and warn if not set to YES or NO. +#: +#: Args: +#: $1 (str): the name of the variable to test to +#: +#: Returns: +#: 0 (truthy) iff ``yes`` (et al), 1 (falsy) otherwise. +#: +#: This function warns if other than proper YES/NO values are found. +#: +checkyesno() { + local _value + + eval _value=\${${1}} + case $_value in + # "yes", "true", "on", or "1" + [Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|[Oo][Nn]|1) + return 0 + ;; + # "no", "false", "off", or "0" + [Nn][Oo]|[Ff][Aa][Ll][Ss][Ee]|[Oo][Ff][Ff]|0) + return 1 + ;; + *) + warn "\${${1}} is not set properly" + return 1 + ;; + esac +} + + +#: +#: Test $1 variable whether it is set to YES. +#: +#: Args: +#: $1 (str): the name of the variable to test to +#: +#: Returns: +#: 0 (truthy) iff ``yes`` (et al), 1 (falsy) otherwise. +#: +#: Contrary to `checkyesno` this function does not warn if the variable +#: contains other values as YES. +#: +checkyes() { + local _value + + eval _value=\${${1}} + case $_value in + # "yes", "true", "on", or "1" + [Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|[Oo][Nn]|1) + return 0 + ;; + *) + return 1 + ;; + esac +} + + +#: #: Ensure that no command line options are given #: #: Args: