has
has copied to clipboard
HAS_ALLOW_UNSAFE only checks lowercase
Needs to be case insenstive ([Yy])
or just an existence check [[ -v HAS_ALLOW_UNSAFE ]]
+1 for case insensitivity
Just existence check might break for someone trying HAS_ALLOW_UNSAFE=N, if we really need to go that route, I would choose a different evn variable name then
Will make it a command line option too.
- [X]
has -usetsHAS_ALLOW_UNSAFE=yesto reuse code below
..when I get to #36 😀
How's this?
-
[X] keep
HAS_ALLOW_UNSAFEso no Breaking Change -
[x] not Bash 4.x dependent (where
extglobis default on) -
[x] save and restore existing
shopt -
[x] case insensitive "y"
- [x] optional "es"
## probably cannot use ${var,,} for lowercase because: darwin
## save extglob nocasematch current
p_shopt=$( shopt -p extglob nocasematch ) && shopt -s extglob nocasematch
if [[ "${HAS_ALLOW_UNSAFE}" = "y?(es)" ]]; then
...
fi
eval "${p_shopt[@]}"
Or, to support HAS_ALLOW_UNSAFE=true
if [[ "${HAS_ALLOW_UNSAFE}" =~ ^(true|y?(es)|only_thursday)$ ]]; then
printf '%s in list.\n' "${HAS_ALLOW_UNSAFE}"
# true
fi