#!/bin/bash

command_to_do() {
  echo "Args $@"

  SYSTEM=false
  UNINSTALL=false
  PUSH=false
  VERSION="debug"

  while getopts "sup:" opt; do
    printf "\n$opt\n"
    case $opt in
      s) echo "Setting SYSTEM to true"
         SYSTEM=true
         ;;
      p) echo "Setting VERSION to $OPTARG"
         PUSH=true
         VERSION=$OPTARG
         ;;
      u) echo "Setting UNINSTALL to true"
         UNINSTALL=true
         ;;
    esac
  done

  printf "\nSystem: $SYSTEM\nVersion: $VERSION\n"

  if [[ $UNINSTALL = true ]]; then
    if [[ $SYSTEM = true ]]; then
      echo "system uninstall"
    else
      echo "non-system uninstall"
    fi
  fi

}

echo
echo "------------ First run:"
command_to_do -s -p release

echo
echo "------------ Second run: (no reset)"
command_to_do -s -p release

echo
echo "------------ Third run (OPTIND reset)"
unset OPTIND
command_to_do -s -p release