-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserve.sh
More file actions
executable file
·40 lines (29 loc) · 1.01 KB
/
serve.sh
File metadata and controls
executable file
·40 lines (29 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/bin/sh
# default values
PORT=8080
APPLICATION_ENV="development"
pointer=1
while [[ $pointer -le $# ]]; do
if [[ ${!pointer} != "-"* ]]; then ((pointer++)) # not a parameter flag so advance pointer
else
param=${!pointer}
((pointer_plus = pointer + 1))
slice_len=1
case $param in
# paramater-flags with arguments
-e|--environment) APPLICATION_ENV=${!pointer_plus}; ((slice_len++));;
-p|--port) PORT=${!pointer_plus}; ((slice_len++));;
# binary flags
#-v|--quiet) quiet=true;;
# -d) debug=true;;
esac
# splice out pointer frame from positional list
[[ $pointer -gt 1 ]] \
&& set -- $"{@:1:((pointer - 1))}" $"{@:((pointer + $slice_len)):$#}"\
|| set -- $"{@:((pointer + $slice_len)):$#}";
fi
done
echo "\n"
echo "Listening to port: \033[32m$PORT\033[0m"
echo "Application environment: \033[32m$APPLICATION_ENV\033[0m \n\n"
env APPLICATION_ENV=${APPLICATION_ENV} php -S localhost:${PORT} -t public