File tree Expand file tree Collapse file tree 4 files changed +25
-10
lines changed
Expand file tree Collapse file tree 4 files changed +25
-10
lines changed Original file line number Diff line number Diff line change 33.idea
44.DS_Store
55protogen
6+ temp
Original file line number Diff line number Diff line change @@ -4,7 +4,8 @@ syntax = "proto3";
44// but different package
55package foo ;
66
7- option go_package = "github.com/tokopedia/gripmock/example/multi-package" ;
7+ // simulating dummy private repo
8+ option go_package = "github.com/my/private/repo/multi-package" ;
89
910message Response {
1011 string response = 1 ;
Original file line number Diff line number Diff line change @@ -4,29 +4,39 @@ protos=("$@")
44
55for proto in " ${protos[@]} "
66do
7- if grep ' ^option go_package' $proto ; then
8- echo " option go_package detected in $proto , no need to append"
9- exit 1
10- fi
11- done
12-
13- for proto in " ${protos[@]} "
14- do
7+ # if it's a directory then skip
158 if [[ -d $proto ]]; then
169 continue
1710 fi
1811
12+ # example $proto: example/foo/bar/hello.proto
13+
14+ # get string from left until the last /
15+ # example value: example/foo/bar/
1916 dir=${proto%/* }
17+
18+ # get string from right until the first /
19+ # example value: hello.proto
2020 file=${proto##*/ }
2121
2222 newdir=" protogen/$dir "
2323 newfile=" $newdir /$file "
24+
2425 # copy to protogen directory
25- mkdir -p " $newdir " && cp " $proto " " $_ "
26+ mkdir -p " $newdir " && \
27+ cp " $proto " " $_ " && \
28+
29+ # Force remove any declaration of go_package
30+ # then replace it with our own declaration below
31+ sed -i ' s/^option go_package.*$//g' $newfile
2632
33+
34+ # get the line number of "syntax" declaration
2735 syntaxLineNum=" $( grep -n " syntax" " $newfile " | head -n 1 | cut -d: -f1) "
2836
2937 goPackageString=" option go_package = \" github.com/tokopedia/gripmock/protogen/$dir \" ;"
38+
39+ # append our own go_package delcaration just below "syntax" declaration
3040 sed -i " ${syntaxLineNum} s~$~\n$goPackageString ~" $newfile
3141 echo $newfile
3242done
Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ require (
99 github.com/kr/pretty v0.2.0 // indirect
1010 github.com/lithammer/fuzzysearch v1.1.1
1111 github.com/stretchr/testify v1.6.1
12+ github.com/tokopedia/gripmock/protogen v0.0.0 // indirect
1213 golang.org/x/net v0.0.0-20201110031124-69a78807bb2b // indirect
1314 golang.org/x/sys v0.0.0-20201112073958-5cba982894dd // indirect
1415 golang.org/x/text v0.3.4 // indirect
@@ -19,3 +20,5 @@ require (
1920 gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect
2021 gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776 // indirect
2122)
23+
24+ replace github.com/tokopedia/gripmock/protogen v0.0.0 => ./protogen
You can’t perform that action at this time.
0 commit comments