Skip to content

Commit

Permalink
ctbcap: optimize options check
Browse files Browse the repository at this point in the history
- add redundant inputs check
  • Loading branch information
KFERMercer committed Jan 3, 2025
1 parent a983e76 commit d719a93
Showing 1 changed file with 12 additions and 22 deletions.
34 changes: 12 additions & 22 deletions ctbcap
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,6 @@ genesis_juicer() {
c)
[ "$(echo "${OPTARG}" | cut -c1)" = "-" ] && {
echo "(ERROR) No Cut Time Specified!" >&2
echo >&2
echo "See [ $0 -h ] for help." >&2
return 1
}
CUT_TIME=${OPTARG}
Expand All @@ -151,8 +149,6 @@ genesis_juicer() {
f)
[ "$(echo "${OPTARG}" | cut -c1)" = "-" ] && {
echo "(ERROR) No Recording Saving Path Specified!" >&2
echo >&2
echo "See [ $0 -h ] for help." >&2
return 1
}
SAVE_PATH=${OPTARG}
Expand All @@ -162,17 +158,13 @@ genesis_juicer() {
o)
[ "$(echo "${OPTARG}" | cut -c1)" = "-" ] && {
echo "(ERROR) No Log Saving Path Specified!" >&2
echo >&2
echo "See [ $0 -h ] for help." >&2
return 1
}
LOG_PATH=${OPTARG}
;;
p)
[ "$(echo "${OPTARG}" | cut -c1)" = "-" ] && {
echo "(ERROR) No Cut Time Specified!" >&2
echo >&2
echo "See [ $0 -h ] for help." >&2
return 1
}
PLATFORM=${OPTARG}
Expand All @@ -183,9 +175,7 @@ genesis_juicer() {
return 2
;;
\?)
echo "(ERROR) Invalid Option [${OPTARG}] !" >&2
echo >&2
echo "See [ $0 -h ] for help."
echo "(ERROR) Invalid Option: [${OPTARG}] !" >&2
return 1
;;
:)
Expand All @@ -195,21 +185,22 @@ genesis_juicer() {
o) echo "(ERROR) No Log Saving Path Specified!" >&2 ;;
p) echo "(ERROR) No Platform Specified!" >&2 ;;
esac
echo >&2
echo "See [ $0 -h ] for help." >&2
return 1
;;
esac
done
shift $((OPTIND - 1))
[ -n "$2" ] && {
shift 1
echo "(ERROR) Invalid Inputs: [$*] !" >&2
return 1
}
[ -n "$1" ] && MODEL=$1

defaulting_args

[ -z "${MODEL}" ] && {
echo "(ERROR) No Username or URL Specified!" >&2
echo >&2
echo "See [ $0 -h ] for help." >&2
return 1
}
# Assume ${MODEL} contain some URL form, process & cut invalid chars.
Expand All @@ -224,8 +215,6 @@ genesis_juicer() {
[ -z "${_MODEL}" ] && local _MODEL="$(echo "${MODEL}" | tr '[:upper:]' '[:lower:]'| grep -oE '[a-z0-9_-]+' | head -n 1)"
[ -z "${_MODEL}" ] && {
echo "(ERROR) Invalid Username or URL! [${MODEL}]" >&2
echo >&2
echo "See [ $0 -h ] for help." >&2
return 1
}
[ -n "${_MODEL}" ] && MODEL="${_MODEL}"
Expand All @@ -242,17 +231,13 @@ genesis_juicer() {
;;
*)
echo "(ERROR) Unknown Platform: [${PLATFORM}] !" >&2
echo >&2
echo "See [ $0 -h ] for help." >&2
return 1
;;
esac

CUT_TIME=$(echo "${CUT_TIME}" | cut -c -9) #Cut to INT range
[ -z "$(echo "${CUT_TIME}" | grep -oE '^[0-9]+$')" ] && {
echo "(ERROR) Cut Time Must be Some INT Number! [${CUT_TIME}]" >&2
echo >&2
echo "See [ $0 -h ] for help." >&2
return 1
}

Expand Down Expand Up @@ -554,7 +539,12 @@ watchdog() {
echo "Simping Streamer: [${MODEL}] (${PLATFORM})"
;;
2) echo; exit 0 ;;
*) echo >&2; exit 1 ;;
*)
echo >&2
echo "See [ $0 -h ] for help." >&2
echo >&2
exit 1
;;
esac

echo
Expand Down

0 comments on commit d719a93

Please sign in to comment.