Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HAS_ALLOW_UNSAFE only checks lowercase #35

Open
virgilwashere opened this issue May 22, 2019 · 2 comments
Open

HAS_ALLOW_UNSAFE only checks lowercase #35

virgilwashere opened this issue May 22, 2019 · 2 comments
Labels
good first issue Easy enough to contribute without much context hacktoberfest help wanted

Comments

@virgilwashere
Copy link
Contributor

Needs to be case insenstive ([Yy])
or just an existence check [[ -v HAS_ALLOW_UNSAFE ]]

@kdabir
Copy link
Owner

kdabir commented May 26, 2019

+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

@kdabir kdabir added help wanted good first issue Easy enough to contribute without much context labels May 26, 2019
@virgilwashere
Copy link
Contributor Author

virgilwashere commented Jun 5, 2019

Will make it a command line option too.

  • has -u sets HAS_ALLOW_UNSAFE=yes to reuse code below

..when I get to #36 😀

How's this?

  • keep HAS_ALLOW_UNSAFE so no Breaking Change

  • not Bash 4.x dependent (where extglob is default on)

  • save and restore existing shopt

  • case insensitive "y"

    • 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Easy enough to contribute without much context hacktoberfest help wanted
Projects
None yet
Development

No branches or pull requests

2 participants