cmd=$(fc -nl -1)
#!/bin/bash
source $TOOLS/script/ENVS64.bash
source $TOOLS/script/use_python3.sh

fac=$(echo $FACILITY_ROOT | awk -F'/' '{print $NF}')

ERR_OUT="0"
RET_IOC="0"

usage(){
	echo "Usage:" 1>&2
	echo "	[ INPUT STREAM ] | invalidPVs.bash [ -e ] [ -i ]" 1>&2
	echo "" 1>&2
	echo "Note:" 1>&2
	echo "	INPUT STREAM is optional. invalidPVs.bash does allow user to type PVs manually." 1>&2
	echo "	If entering manually, typing 'exit' will continue the program." 1>&2
	echo "" 1>&2
	echo "Options:" 1>&2
	echo "	-h  Show this message and exit" 1>&2
	echo "	-e  Print PV name error making it invalid" 1>&2
	echo "	-i  Print IOC containing incorrect PV name" 1>&2
}
exit_abnormal(){
	usage
	exit 1
}

while getopts ":ei" options; do
	case "${options}" in
		e) ERR_OUT="1";;
		i) RET_IOC="1";;
		:) echo "Error: -${OPTARG} requires an argument."
			exit_abnormal;;
		*) exit_abnormal;;
	esac
done

echo $cmd
(cd $TOOLS/script/ValidatePVs \
        && python invalidPVs.py \
        input_files/devices.json \
        input_files/${fac}_areas.json \
        $ERR_OUT \
        $RET_IOC)
exit 0
