Skip to content

Commit

Permalink
add imports args (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
jekiapp authored Sep 19, 2019
1 parent 845771c commit 00bf2cf
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions gripmock.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func main() {
adminport := flag.String("admin-port", "4771", "Port of stub admin server")
adminBindAddr := flag.String("admin-listen", "", "Adress the admin server will bind to. Default to localhost, set to 0.0.0.0 to use from another machine")
stubPath := flag.String("stub", "", "Path where the stub files are (Optional)")
wktDir := flag.String("wkt-dir", "/protobuf", "Directory of well-known-types protos.")
imports := flag.String("imports", "/protobuf", "comma separated imports path. default path /protobuf is where gripmock Dockerfile install WKT protos")
// for backwards compatibility
if os.Args[1] == "gripmock" {
os.Args = append(os.Args[:1], os.Args[2:]...)
Expand Down Expand Up @@ -57,14 +57,16 @@ func main() {
log.Fatal("Need atleast one proto file")
}

importDirs := strings.Split(*imports, ",")

// generate pb.go and grpc server based on proto
generateProtoc(protocParam{
protoPath: protoPaths,
adminPort: *adminport,
grpcAddress: *grpcBindAddr,
grpcPort: *grpcPort,
output: output,
wktPath: *wktDir,
imports: importDirs,
})

// build the server
Expand Down Expand Up @@ -96,7 +98,7 @@ type protocParam struct {
grpcAddress string
grpcPort string
output string
wktPath string
imports []string
}

func generateProtoc(param protocParam) {
Expand All @@ -108,7 +110,9 @@ func generateProtoc(param protocParam) {

args := []string{"-I", protodir}
// include well-known-types
args = append(args, "-I", param.wktPath)
for _, i := range param.imports {
args = append(args, "-I", i)
}
args = append(args, param.protoPath...)
args = append(args, "--go_out=plugins=grpc:"+param.output)
args = append(args, fmt.Sprintf("--gripmock_out=admin-port=%s,grpc-address=%s,grpc-port=%s:%s",
Expand Down

0 comments on commit 00bf2cf

Please sign in to comment.