osmith has submitted this change. (
https://gerrit.osmocom.org/c/osmo-dev/+/34699?usp=email )
Change subject: ttcn3.sh: add getopts
......................................................................
ttcn3.sh: add getopts
Add getopts parsing. The idea was to add support for setting a different
IMAGE_SUFFIX argument, but later on it became clear it is not worth
implementing here. Add the getopts logic anyway because it can be used
to add other arguments in the future.
Change-Id: If55a982d92b2a24a175ab7f3a8f048f054033dc2
---
M ttcn3/ttcn3.sh
1 file changed, 45 insertions(+), 9 deletions(-)
Approvals:
osmith: Looks good to me, approved; Verified
diff --git a/ttcn3/ttcn3.sh b/ttcn3/ttcn3.sh
index 74e87cc..3563062 100755
--- a/ttcn3/ttcn3.sh
+++ b/ttcn3/ttcn3.sh
@@ -1,6 +1,6 @@
#!/bin/sh -e
-PROJECT="$1"
-PROJECT_UPPER="$(echo "$PROJECT" | tr '[:lower:]'
'[:upper:]')"
+PROJECT=""
+PROJECT_UPPER=""
DIR_OSMODEV="$(readlink -f "$(dirname $0)/..")"
DIR_MAKE="${DIR_MAKE:-${DIR_OSMODEV}/ttcn3/make}"
DIR_OUTPUT="${DIR_OUTPUT:-${DIR_OSMODEV}/ttcn3/out}"
@@ -14,15 +14,36 @@
DOCKER_IMG_BUILD="debian-bookworm-build"
DOCKER_IMG_TITAN="debian-bookworm-titan"
+parse_args() {
+ while getopts 'h' OPTION; do
+ case "$OPTION" in
+ h|*)
+ local name="$(basename $0)"
+ echo "usage: $name [-h] PROJECT"
+ echo "arguments:"
+ echo " -h show help"
+ echo " PROJECT the testsuite project to run"
+ echo "examples:"
+ echo " $name bsc"
+ echo " $name bsc-sccplite"
+ echo " $name hlr"
+ exit 1
+ ;;
+ esac
+ done
+ shift "$(($OPTIND - 1))"
+
+ if [ "$#" != "1" ]; then
+ parse_args -h
+ fi
+
+ PROJECT="$1"
+ PROJECT_UPPER="$(echo "$PROJECT" | tr '[:lower:]'
'[:upper:]')"
+}
+
check_usage() {
- local name="$(basename $0)"
if [ -z "$PROJECT" ]; then
- echo "usage: $name PROJECT"
- echo "examples:"
- echo " * $name bsc"
- echo " * $name bsc-sccplite"
- echo " * $name hlr"
- exit 1
+ parse_args -h
fi
}
@@ -359,6 +380,7 @@
echo "---"
}
+parse_args "$@"
check_usage
check_ttcn3_install
setup_dir_make
--
To view, visit
https://gerrit.osmocom.org/c/osmo-dev/+/34699?usp=email
To unsubscribe, or for help writing mail filters, visit
https://gerrit.osmocom.org/settings
Gerrit-Project: osmo-dev
Gerrit-Branch: master
Gerrit-Change-Id: If55a982d92b2a24a175ab7f3a8f048f054033dc2
Gerrit-Change-Number: 34699
Gerrit-PatchSet: 1
Gerrit-Owner: osmith <osmith(a)sysmocom.de>
Gerrit-Reviewer: osmith <osmith(a)sysmocom.de>
Gerrit-MessageType: merged