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

protoc-gen-elm: don't print input by default #24

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
24 changes: 23 additions & 1 deletion protoc-gen-elm/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,16 @@ func main() {
log.Fatalf("Could not unmarshal request: %v", err)
}

opts := parseParam(req.GetParameter())

// Remove useless source code data.
for _, inFile := range req.GetProtoFile() {
inFile.SourceCodeInfo = nil
}

log.Printf("Input data: %v", proto.MarshalTextString(req))
if _, ok := opts["debug"]; ok {
log.Printf("Input data: %v", proto.MarshalTextString(req))
}

resp := &plugin.CodeGeneratorResponse{}

Expand Down Expand Up @@ -131,6 +135,24 @@ func main() {
}
}

// parseParam parses the comma-separated list of key=value pairs in the
// CodeGeneratorRequest's parameter into a map.
func parseParam(parameter string) map[string]string {
opts := make(map[string]string)

for _, token := range strings.Split(parameter, ",") {
token = strings.TrimSpace(token)

if k := strings.Index(token, "="); k < 0 {
opts[token] = ""
} else {
opts[token[0:k]] = token[k+1:]
}
}

return opts
}

func hasMapEntries(inFile *descriptor.FileDescriptorProto) bool {
for _, m := range inFile.GetMessageType() {
if hasMapEntriesInMessage(m) {
Expand Down