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

Handle unknown options better #4

Open
JonTheNiceGuy opened this issue Jun 23, 2021 · 0 comments
Open

Handle unknown options better #4

JonTheNiceGuy opened this issue Jun 23, 2021 · 0 comments
Labels
enhancement New feature or request

Comments

@JonTheNiceGuy
Copy link
Owner

Add unknown_option=() to the parse_param() function.

In the block -?*), replace the existing code with:

-?*)
      empty_command=0
      exists=0
      for i in "${!unknown_option[@]}"
      do
        if [ "${unknown_option[$i]}" == "${1}" ]
        then
          exists=1
        fi
      done
      [ "$exists" -eq 0 ] && unknown_option+=("${1}")
      ;;

Re-order the [[ $empty_command -eq 1 ]] && usage and $unknown_option part to use:

  for i in "${!unknown_option[@]}"
  do
    empty_command=1
    msg "[ERROR] ${RED}Unknown option provided: ${unknown_option[$i]}${NOFORMAT}"
  done
  [[ $empty_command -eq 1 ]] && usage

Note that this doesn't handle something like: some_command --unknown "with value" - you'd need to check whether the $2 contains a non-hyphen prefixed string and if it does, add it on to the unknown_option array member.

@JonTheNiceGuy JonTheNiceGuy added the enhancement New feature or request label Jun 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant