add cli server script
authorMichael Wallner <mike@php.net>
Fri, 20 Dec 2013 15:19:46 +0000 (16:19 +0100)
committerMichael Wallner <mike@php.net>
Fri, 20 Dec 2013 15:19:46 +0000 (16:19 +0100)
bin/cli-server [new file with mode: 0755]

diff --git a/bin/cli-server b/bin/cli-server
new file mode 100755 (executable)
index 0000000..15b4b55
--- /dev/null
@@ -0,0 +1,47 @@
+#!/bin/bash
+
+# record working dir
+OWD=$(pwd)
+
+# chdir to docroot
+cd $(dirname $0)/../public
+
+function addrefpath {
+       path="$1"
+       if test ${path:0:1} != "/"
+       then
+               REFPATH="$OWD/$path$REFPATH"
+       else
+               REFPATH="$path$REFPATH"
+       fi
+}
+
+# override REFPATH
+if test $# -gt 0; then
+       REFPATH=""
+       addrefpath "$1"
+       shift
+       while test $# -gt 0; do
+               addrefpath "$1:"
+               shift
+       done
+fi
+
+if test -z "$REFPATH"
+then
+       printf "Usage:\n\t%s [refpath] ...\n\n" "$(basename $0)"
+       printf "Parameters:\n"
+       printf "\trefpath   path to a markdown reference tree or a colon separated\n"
+       printf "\t          list of those (optional, multiple)\n\n"
+       printf "Environment:\n"
+       printf "\tREFPATH   colon separated list of refpaths\n\n"
+       printf "At least one refpath must be given, either through the environment "
+       printf "with REFPATH or as command line argument.\n\n"
+       exit 1
+fi
+
+export REFPATH
+
+for p in {8000..8100}; do
+       php -S localhost:$p -t . index.php && break
+done