# see: https://github.com/feynmanliang/Unix-tutorial/blob/master/zsh/handling_options
testopts() {
  # $opt will hold the current option
  while getopts ab: opt; do
    # loop continues till options finished
    # see which pattern $opt matches...
    # shellcheck disable=SC2249
    case ${opt} in
      a)
        print Option a set
        ;;
      b)
        print Option b set to "${OPTARG}"
        ;;
      # matches a question mark
      # (and nothing else, see text)
      \?)
        print Bad option, aborting.
        return 1
        ;;
    esac
  done
  # $OPTIND is set to 1 at start of every function and advanced by `getopts`
  [ "${OPTIND}" -gt 1 ] && shift "$((OPTIND - 1))"
  printf '%s\n' "Remaining arguments are: $*"
}
