Improves the command input options

This commit is contained in:
Llewellyn van der Merwe 2023-02-13 15:37:46 +02:00
parent 6ff9913276
commit ae9d304c0b
Signed by: Llewellyn
GPG Key ID: A9201372263741E7

View File

@ -1235,144 +1235,94 @@ while :; do
runUpdate runUpdate
shift shift
;; ;;
-e | --env) # Takes an option argument; ensure it has been specified. -e=* | --env=*)
if [ "$2" ]; then VDM_ENV_FILE_PATH=${1#*=}
VDM_ENV_FILE_PATH=$2 if [ -z "$VDM_ENV_FILE_PATH" ]; then
shift
else
echo '[error] "--env" requires a non-empty option argument.' echo '[error] "--env" requires a non-empty option argument.'
exit 17 exit 17
fi fi
;; ;;
-e=?* | --env=?*) --conf=* | --config=*)
VDM_ENV_FILE_PATH=${1#*=} # Delete everything up to "=" and assign the remainder. VDM_PACKAGE_CONF_FILE=${1#*=}
;; if [ -z "$VDM_PACKAGE_CONF_FILE" ]; then
-e= | --env=) # Handle the case of an empty --packages=
echo '[error] "--env=" requires a non-empty option argument.'
exit 17
;;
--conf | --config) # Takes an option argument; ensure it has been specified.
if [ "$2" ]; then
VDM_PACKAGE_CONF_FILE=$2
shift
else
echo '[error] "--conf" requires a non-empty option argument.' echo '[error] "--conf" requires a non-empty option argument.'
exit 17 exit 17
fi fi
;; ;;
--conf=?* | --config=?*) -p=* | --packager=*)
VDM_PACKAGE_CONF_FILE=${1#*=} # Delete everything up to "=" and assign the remainder. VDM_PACKAGER=${1#*=}
;; if [ -z "$VDM_PACKAGER" ]; then
--conf= | --config=) # Handle the case of an empty --packages=
echo '[error] "--conf=" requires a non-empty option argument.'
exit 17
;;
-p | --packager) # Takes an option argument; ensure it has been specified.
if [ "$2" ]; then
VDM_PACKAGER=$2
shift
else
echo '[error] "--packager" requires a non-empty option argument.' echo '[error] "--packager" requires a non-empty option argument.'
exit 17 exit 17
fi fi
;; ;;
-p=?* | --packager=?*) -pu=* | --packager-url=*)
VDM_PACKAGER=${1#*=} # Delete everything up to "=" and assign the remainder. VDM_PACKAGER_URL=${1#*=}
;; if [ -z "$VDM_PACKAGER_URL" ]; then
-p= | --packager=) # Handle the case of an empty --packages=
echo '[error] "--packager=" requires a non-empty option argument.'
exit 17
;;
-pu | --packager-url) # Takes an option argument; ensure it has been specified.
if [ "$2" ]; then
VDM_PACKAGER_URL=$2
shift
else
echo '[error] "--packager-url" requires a non-empty option argument.' echo '[error] "--packager-url" requires a non-empty option argument.'
exit 17 exit 17
fi fi
;; ;;
-pu=?* | --packager-url=?*) -t=* | --token=*)
VDM_PACKAGER_URL=${1#*=} # Delete everything up to "=" and assign the remainder. VDM_GLOBAL_TOKEN=${1#*=}
;; if [ -z "$VDM_GLOBAL_TOKEN" ]; then
-pu= | --packager-url=) # Handle the case of an empty --packager-url=
echo '[error] "--packager-url=" requires a non-empty option argument.'
exit 17
;;
-t | --token) # Takes an option argument; ensure it has been specified.
if [ "$2" ]; then
VDM_GLOBAL_TOKEN=$2
shift
else
echo '[error] "--token" requires a non-empty option argument.' echo '[error] "--token" requires a non-empty option argument.'
exit 17 exit 17
fi fi
;; ;;
-t=?* | --token=?*) -a=* | --api=*)
# shellcheck disable=SC2034 VDM_GLOBAL_API=${1#*=}
VDM_GLOBAL_TOKEN=${1#*=} # Delete everything up to "=" and assign the remainder. if [ -z "$VDM_GLOBAL_API" ]; then
;;
-t= | --token=) # Handle the case of an empty --packages=
echo '[error] "--token=" requires a non-empty option argument.'
exit 17
;;
-a | --api) # Takes an option argument; ensure it has been specified.
if [ "$2" ]; then
VDM_GLOBAL_API=$2
shift
else
echo '[error] "--api" requires a non-empty option argument.' echo '[error] "--api" requires a non-empty option argument.'
exit 17 exit 17
fi fi
;; ;;
-a=?* | --api=?*) -u=* | --url=*)
# shellcheck disable=SC2034 VDM_GLOBAL_URL=${1#*=}
VDM_GLOBAL_API=${1#*=} # Delete everything up to "=" and assign the remainder. if [ -z "$VDM_GLOBAL_URL" ]; then
;;
-a= | --api=) # Handle the case of an empty --packages=
echo '[error] "--api=" requires a non-empty option argument.'
exit 17
;;
-u | --url) # Takes an option argument; ensure it has been specified.
if [ "$2" ]; then
VDM_GLOBAL_URL=$2
shift
else
echo '[error] "--url" requires a non-empty option argument.' echo '[error] "--url" requires a non-empty option argument.'
exit 17 exit 17
fi fi
;; ;;
-u=?* | --url=?*) -v=* | --verbosity=*)
# shellcheck disable=SC2034 VDM_VERBOSITY=${1#*=}
VDM_GLOBAL_URL=${1#*=} # Delete everything up to "=" and assign the remainder. if [ -z "$VDM_VERBOSITY" ]; then
;; echo '[error] "--verbosity" requires a non-empty option argument.'
-u= | --url=) # Handle the case of an empty --packages=
echo '[error] "--url=" requires a non-empty option argument.'
exit 17 exit 17
fi
;; ;;
*) # Default case: No more options, so break out of the loop. --) # End of all options.
break ;; shift
break
;;
-?*)
printf '[error] Unknown option: %s\n' "$1" >&2
exit 1
;;
*) # Default case: If no more options then break out of the loop.
break
esac esac
shift shift
done done
# load local environment variables # load local environment variables
# shellcheck disable=SC1090 if [ -f "$VDM_ENV_FILE_PATH" ]; then
[ -f "${VDM_ENV_FILE_PATH}" ] && source "${VDM_ENV_FILE_PATH}" # shellcheck disable=SC1090
source "$VDM_ENV_FILE_PATH"
fi
# if path not set try $PWD path (so you can open a folder that has .octojpack file and it will be loaded) # if path not set try $PWD path (so you can open a folder that has .octojpack file and it will be loaded)
tmp_path="$PWD/.${PROGRAM_CODE}" tmp_path="$PWD/.${PROGRAM_CODE}"
VDM_PACKAGE_CONF_FILE="${VDM_PACKAGE_CONF_FILE:-$tmp_path}" VDM_PACKAGE_CONF_FILE=${VDM_PACKAGE_CONF_FILE:-$tmp_path}
# check if the config is passed via a URL # check if the config is passed via a URL
if [[ "${VDM_PACKAGE_CONF_FILE}" =~ ^"http:" ]] || [[ "${VDM_PACKAGE_CONF_FILE}" =~ ^"https:" ]]; then if [[ "$VDM_PACKAGE_CONF_FILE" =~ ^"http:" ]] || [[ "$VDM_PACKAGE_CONF_FILE" =~ ^"https:" ]]; then
# shellcheck disable=SC2143 if [[ $(wget -S --spider "$VDM_PACKAGE_CONF_FILE" 2>&1 | grep 'HTTP/1.1 200 OK') ]]; then
if [[ $(wget -S --spider "${VDM_PACKAGE_CONF_FILE}" 2>&1 | grep 'HTTP/1.1 200 OK') ]]; then
mkdir -p "/home/$USER/.config/${PROGRAM_CODE}" mkdir -p "/home/$USER/.config/${PROGRAM_CODE}"
wget --quiet "${VDM_PACKAGE_CONF_FILE}" -O "/home/$USER/.config/${PROGRAM_CODE}/conf.json" wget --quiet "$VDM_PACKAGE_CONF_FILE" -O "/home/$USER/.config/${PROGRAM_CODE}/conf.json"
VDM_PACKAGE_CONF_FILE="/home/$USER/.config/${PROGRAM_CODE}/conf.json" VDM_PACKAGE_CONF_FILE="/home/$USER/.config/${PROGRAM_CODE}/conf.json"
else else
echo >&2 "[error] The config:${VDM_PACKAGE_CONF_FILE} is not a valid URL. Aborting." echo >&2 "[error] The config:$VDM_PACKAGE_CONF_FILE is not a valid URL. Aborting."
exit 18 exit 18
fi fi
fi fi