-
Notifications
You must be signed in to change notification settings - Fork 0
/
docker_protoc_gen_recurse.sh
executable file
·58 lines (54 loc) · 1.41 KB
/
docker_protoc_gen_recurse.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
#! /bin/bash
MYDIR=$(cd `dirname ${0}`; pwd)
GIT_OUTPUT_DIR=$2
PYTHON_DIR=${GIT_OUTPUT_DIR}/"python"
GO_DIR=${GIT_OUTPUT_DIR}/"golang"
CSHARP_DIR=${GIT_OUTPUT_DIR}/"csharp"
if [[ ! -d ${PYTHON_DIR} ]]; then
mkdir -p ${PYTHON_DIR}
fi
if [[ ! -d ${GO_DIR} ]]; then
mkdir -p ${GO_DIR}
fi
if [[ ! -d ${CSHARP_DIR} ]]; then
mkdir -p ${CSHARP_DIR}
fi
function read_dir(){
for file in `ls $1`
do
if [[ -d $1"/"$file ]] #注意此处之间一定要加上空格,否则会报错
then
read_dir $1/${file}
else
# 取文件后缀
extension=${file##*.}
if [[ ${extension} == "proto" ]]
then
cur_path=`pwd`
now_path=${cur_path}/$1
echo ${now_path}/${file}
docker run --rm -v ${MYDIR}:${MYDIR} -w $(pwd) znly/protoc -I ${now_path} \
--python_out=${PYTHON_DIR} \
--csharp_out ${CSHARP_DIR} \
--go_out ${GO_DIR} \
${now_path}/${file}
fi
fi
done
}
if [[ $# == 0 ]]; then
echo $#
echo "you must choose a dir for proto."
exit
fi
if [[ $# > 2 ]]; then
echo $#
echo "args more than 2!"
exit
fi
if [[ ! -d $1 ]]; then
ls
echo "$1 does not exists in this dir."
exit
fi
read_dir $1