#!/bin/bash

## Copyright (C) 2012 - 2025 ENCRYPTED SUPPORT LLC <adrelanos@whonix.org>
## See the file COPYING for copying conditions.

parse_cmd_options() {
   ## If systemcheck is run without command line arguments,
   ## $1 will not exist.

   ## defaults
   ## adding --silent to curl to suppress output
   CURL_VERBOSE="--silent"

   ## Thanks to:
   ## http://mywiki.wooledge.org/BashFAQ/035

   while :
   do
       case $1 in
           -h | --help | -\?)
               help_cli
               EXIT_CODE="0"
               cleanup
               return 0
               ;;
           -v | --verbose)
               verbose="$(( $verbose + 1 ))"
               shift
               ;;
           -e | --debug)
               echo "$SCRIPTNAME debug output..."
               echo "Script running as $(whoami)"
               set -x
               CURL_VERBOSE=""
               shift
               ;;
           -f | --function)
               FUNCTION="$2"
               if [ "$FUNCTION" = "" ]; then
                  FUNCTION="none"
                  shift
               else
                  shift 2
               fi
               ;;
           -f | --mode)
               MODE="$2"
               shift 2
               ;;
           -m | --minimal)
               MINIMAL="1"
               shift
               ;;
           --pin-tpo-cert)
               PIN_TPO_CERT="true"
               shift
               ;;
           --no-pin-tpo-cert)
               PIN_TPO_CERT="false"
               shift
               ;;
           --no-del-tmp)
               DEL_TMP="false"
               shift
               ;;
           --gui)
               GUI="true"
               shift
               ;;
           --cli)
               CLI="true"
               shift
               ;;
           --show-ip)
               show_ip="true"
               shift
               ;;
           --leak-test | --leak-tests | --leaktest | --leaktests | --ip-test | --iptest | --ip-tests | --iptests)
               leak_tests="true"
               shift
               ;;
           --)
               shift
               break
               ;;
           -*)
               echo "$SCRIPTNAME unknown option: $1" >&2
               EXIT_CODE="1"
               cleanup "1"
               return 0
               ;;
           *)
               break
               ;;
       esac
   done

   ## If there are input files (for example) that follow the options, they
   ## will remain in the "$@" positional parameters.
}
