Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Import args #28

Merged
merged 1 commit into from
Sep 19, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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