-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtc.sh
114 lines (98 loc) · 2.88 KB
/
tc.sh
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#!/bin/bash
need_cmd() {
if ! check_cmd "$1"; then
err "need '$1' (command not found)"
fi
}
check_cmd() {
command -v "$1" > /dev/null 2>&1
}
err() {
say "$1" >&2
exit 1
}
say() {
printf "TRIER: %s\n" "$1"
}
drun_ddj3base(){
docker run -it --rm -p 8443:8443 -v "${PWD}:/home/coder/project" dltdojo/ddj3base:mad-white --allow-http --no-auth
}
check_all(){
need_cmd jq
need_cmd bash
}
build_book(){
usage &> mdbook/src/cmd-help.txt
pushd mdbook
mdbook build --dest-dir ../docs
popd
}
serve_book(){
pushd mdbook
mdbook serve
popd
}
#
# gen-proto-doc PROTOS_DIR DEST_FILE
# [grpc-ecosystem/grpc-gateway: gRPC to JSON proxy generator following the gRPC HTTP spec](https://github.com/grpc-ecosystem/grpc-gateway)
# go get -u github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway
# go get -u github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger
# go get -u github.com/golang/protobuf/protoc-gen-go
#
gen_proto_doc(){
set -x
PROTOS_DIR=$1
MDFILE=md-proto-gen-tmp.md
DEST_FILE=$2
pushd $PROTOS_DIR
rm /tmp/$MDFILE
find . -type f \
-not -path "./google/protobuf/*" \
-not -path "./github.com/gogo/protobuf/gogoproto/*" \
-not -path "./googleapis/google/api/*" \
-name '*.proto' | xargs protoc -I. -I/usr/local/include \
-I$GOPATH/src \
-I$GOPATH/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis \
--doc_out=/tmp --doc_opt=markdown,$MDFILE
#sed -i "1i# ProtocolBuffer Doc\n## Generated Date:$(date --iso-8601=seconds)\n<!-- toc -->" /tmp/$MDFILE
sed -i "1i# Generated Date:$(date --iso-8601=seconds)\n" /tmp/$MDFILE
echo -e '\n# Protos File Tree\n```\n' >> /tmp/$MDFILE
tree -P "*.proto" . >> /tmp/$MDFILE
echo -e '\n```\n' >> /tmp/$MDFILE
echo -e "# Protobuf sources\n" >> /tmp/$MDFILE
find . -type f \
-not -path "./google/protobuf/*" \
-not -path "./github.com/gogo/protobuf/gogoproto/*" \
-not -path "./googleapis/google/api/*" \
-name '*.proto' \
-exec echo -e '\n## src:{}\n```proto\n' \; -exec cat {} \; -exec echo -e '\n```\n' \; >> /tmp/$MDFILE
cp -f /tmp/$MDFILE $DEST_FILE
popd
}
usage() {
cat 1>&2 <<EOF
DLTDOJO CLI Tool
USAGE:
bash tc.sh [FLAGS] [OPTIONS]
FLAGS:
--drun 啟動 ddj3base 容器服務
--build-book 使用 mdbook 編譯本書
--serve-book 使用 mdbook 啟動同步編輯網頁服務
-c, --check check need commands
-h, --help Prints help information
-v, --version Prints version information
EOF
}
case "$1" in
--drun) shift; drun_ddj3base $@ ;;
--build-book) shift; build_book $@ ;;
--serve-book) shift; serve_book $@ ;;
--gen-proto-doc) shift; gen_proto_doc $@ ;;
-h|--help)
usage
exit 0
;;
*) usage
exit 0
;;
esac