use getopt for more robust option handling

This commit is contained in:
Michael Becker 2025-01-17 21:54:11 -05:00
parent f98b89c44a
commit 85b7754138
2 changed files with 51 additions and 20 deletions

View File

@ -3,10 +3,25 @@
# update .NET # update .NET
REBUILD=false REBUILD=false
if [ "$1" == "--rebuild" ]; then
vars=$(getopt -o r -l rebuild -- "$@")
if [ $? -ne 0 ]; then
echo "usage: docker-build [--rebuild]"
exit
fi
eval set -- $vars
for opt; do
case "$opt" in
-r|--rebuild)
REBUILD=true REBUILD=true
shift shift
fi ;;
esac
done
if [ "$REBUILD" == "true" ]; then if [ "$REBUILD" == "true" ]; then
pushd ../mocha-dotnet/mocha-dotnet/src/app/Mocha.Oms.Server pushd ../mocha-dotnet/mocha-dotnet/src/app/Mocha.Oms.Server

View File

@ -2,7 +2,39 @@
USE_SSL=false USE_SSL=false
./docker-build ${1+"$@"} vars=$(getopt -o p:sr --long port:,enable-ssh,rebuild -- "$@")
if [ $? -ne 0 ]; then
echo "usage: docker-run [-r, --rebuild] [-p, --port PORTFORWARD] [-s, --enable-ssh]"
exit
fi
eval set -- "$vars"
PORT_FORWARD=""
ENABLE_SSH=""
BUILD_OPTS=""
for opt; do
case "$opt" in
-p|--port)
PORT_FORWARD=$2
shift 2
;;
-s|--enable-ssh)
ENABLE_SSH="true"
shift
;;
-r|--rebuild)
BUILD_OPTS+=" --rebuild"
shift
;;
esac
done
./docker-build $BUILD_OPTS
Q=$? Q=$?
if [ $Q -ne 0 ]; then if [ $Q -ne 0 ]; then
@ -11,22 +43,6 @@ if [ $Q -ne 0 ]; then
fi fi
PORT_FORWARD=""
if [ "$1" == "--port" ]; then
PORT_FORWARD="$2"
shift; shift
fi
ENABLE_SSH=""
if [ "$1" == "--enable-ssh" ]; then
ENABLE_SSH="true"
shift
fi
# generate random UUID for new SUV # generate random UUID for new SUV
# thanks https://stackoverflow.com/questions/34328759 # thanks https://stackoverflow.com/questions/34328759
# SUV_ID=$(hexdump -vn8 -e'2/4 "%08x" 1 "\n"' /dev/urandom) # SUV_ID=$(hexdump -vn8 -e'2/4 "%08x" 1 "\n"' /dev/urandom)