stub2ref do not generate <ns>.md
[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 "Examples:\n"
39 printf "\t\$ REFPATH=refs/foo:refs/bar ./bin/cli-server\n\n"
40 printf "\t\$ ./bin/cli-server refs/*\n\n"
41 printf "\tAt least one refpath must be given, either through the environment\n"
42 printf "\twith REFPATH or as command line argument.\n\n"
43 exit 1
44 fi
45
46 export REFPATH
47
48 for p in {8000..8100}; do
49 ${PHP:-php} -S localhost:$p -t . index.php && break
50 done