]> mj.ucw.cz Git - moe.git/commitdiff
Added a mechanism for overriding configuration settings from the command line.
authorMartin Mares <mj@ucw.cz>
Wed, 19 Mar 2008 13:08:45 +0000 (14:08 +0100)
committerMartin Mares <mj@ucw.cz>
Wed, 19 Mar 2008 13:08:45 +0000 (14:08 +0100)
bin/ev
bin/lib

diff --git a/bin/ev b/bin/ev
index a6189077d9f94b228f471887f7a1d062873345ea..7d5ecc3980c76c83a087fce25de4e048cf0e7bb2 100755 (executable)
--- a/bin/ev
+++ b/bin/ev
@@ -9,8 +9,11 @@ if [ ! -f config -o ! -f bin/lib ] ; then
 fi
 . bin/lib
 . config
+while parse-cmdline "$1" ; do
+       shift
+done
 
-[ -n "$2" -a -z "$4" ] || die "Usage: ev <contestant> <problem> [<program>]"
+[ -n "$2" -a -z "$4" ] || die "Usage: ev [<var>=<value>] <contestant> <problem> [<program>]"
 CONTESTANT=$1
 PROBLEM=$2
 dir-init
diff --git a/bin/lib b/bin/lib
index ae5c4218e94dcf113f699adcc835b9549c85ac38..9c074650b0affc22fe60272994a6a8866e5f66b8 100644 (file)
--- a/bin/lib
+++ b/bin/lib
@@ -488,3 +488,19 @@ function fpc-exit-code
                216)    echo -n "Segmentation fault" ;;
        esac
 }
+
+# A helper function for parsing of command-line overrides of variables
+
+function parse-cmdline
+{
+       if [ "${1#*=}" != "$1" ] ; then
+               local var=${1%%=*}
+               local val=${1#*=}
+               echo >&2 "WANT: {$var} {$val}"
+               eval $var="'$val'"
+               echo >&2 "HAVE: ${!var}"
+               return 0
+       else
+               return 1
+       fi
+}