-
Notifications
You must be signed in to change notification settings - Fork 0
/
doc
executable file
·100 lines (80 loc) · 1.67 KB
/
doc
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/bin/env bash
exdir="$(dirname `readlink -f "$0"`)"
serve_port=8080
cmd=""
#--
help()
{
echo "Usage: doc [options] command
commands
build Generate docs documentation
serve Start webserver
view Open default app to view documentation
commit build + commit doc into docs branch
push push docs branch to origin
options
[ -p | --port ] specify serve port"
exit 2
}
SHORT=p:,h:
LONG=port:,help
OPTS=$(getopt -a -n doc --options $SHORT --longoptions $LONG -- "$@")
VALID_ARGUMENTS=$# # Returns the count of arguments that are in short or long options
if [ "$VALID_ARGUMENTS" -eq 0 ]; then
help
fi
eval set -- "$OPTS"
while :
do
case "$1" in
-p | --port )
serve_port=$2
echo "port specified [$serve_port]"
shift 2
;;
-h | --help)
help
;;
--)
shift;
break
;;
*)
echo "Unexpected option: $1"
help
;;
esac
done
#--[ build ]
if [ "$1" == "build" ]; then
rm -fr "$exdir"/docs
docfx "$exdir"/docfx.json
exit 0
fi
#--[ serve ]
if [ "$1" == "serve" ]; then
docfx "$exdir"/docfx.json --serve -p $serve_port
exit 0
fi
#--[ view ]
if [ "$1" == "view" ]; then
xdg-open http://localhost:$serve_port
fi
#--[ commit ]
DEFAULT_BRANCH=master
if [ "$1" == "commit" ]; then
cd "$exdir"
git stash push && \
git checkout docs && \
git merge $DEFAULT_BRANCH --commit --no-edit && \
./doc build && \
git add -A docs && \
git commit -a -m "doc" && \
git checkout $DEFAULT_BRANCH && \
git stash pop
fi
#--[ push ]
if [ "$1" == "push" ]; then
cd "$exdir"
git push origin docs
fi