15b4b55939fea41497b6436e11b4d7c271df8e96
[mdref/mdref] / bin / cli-server
1 #!/bin/bash
2
3 # record working dir
4 OWD=$(pwd)
5
6 # chdir to docroot
7 cd $(dirname $0)/../public
8
9 function addrefpath {
10 path="$1"
11 if test ${path:0:1} != "/"
12 then
13 REFPATH="$OWD/$path$REFPATH"
14 else
15 REFPATH="$path$REFPATH"
16 fi
17 }
18
19 # override REFPATH
20 if test $# -gt 0; then
21 REFPATH=""
22 addrefpath "$1"
23 shift
24 while test $# -gt 0; do
25 addrefpath "$1:"
26 shift
27 done
28 fi
29
30 if test -z "$REFPATH"
31 then
32 printf "Usage:\n\t%s [refpath] ...\n\n" "$(basename $0)"
33 printf "Parameters:\n"
34 printf "\trefpath path to a markdown reference tree or a colon separated\n"
35 printf "\t list of those (optional, multiple)\n\n"
36 printf "Environment:\n"
37 printf "\tREFPATH colon separated list of refpaths\n\n"
38 printf "At least one refpath must be given, either through the environment "
39 printf "with REFPATH or as command line argument.\n\n"
40 exit 1
41 fi
42
43 export REFPATH
44
45 for p in {8000..8100}; do
46 php -S localhost:$p -t . index.php && break
47 done