Unverified Commit c8927eef authored by Mislav Marohnić's avatar Mislav Marohnić
Browse files

Expand `parse_options` to preserve positional arguments after "--"

parent 4cec3906
Loading
Loading
Loading
Loading
+11 −2
Original line number Diff line number Diff line
@@ -26,10 +26,15 @@ lib() {
  parse_options() {
    OPTIONS=()
    ARGUMENTS=()
    EXTRA_ARGUMENTS=()
    local arg option index

    for arg in "$@"; do
      if [ "${arg:0:1}" = "-" ]; then
    while [ $# -gt 0 ]; do
      arg="$1"
      if [ "$arg" == "--" ]; then
        shift 1
        break
      elif [ "${arg:0:1}" = "-" ]; then
        if [ "${arg:1:1}" = "-" ]; then
          OPTIONS[${#OPTIONS[*]}]="${arg:2}"
        else
@@ -40,10 +45,14 @@ lib() {
            index=$(($index+1))
          done
        fi
        shift 1
      else
        ARGUMENTS[${#ARGUMENTS[*]}]="$arg"
        shift 1
      fi
    done

    EXTRA_ARGUMENTS=("$@")
  }

  if [ "$1" == "--$FUNCNAME" ]; then