One possible solution is to use a bits of the protoreflect library for Go that I've written:
https://godoc.org/github.com/jhump/protoreflect/desc/protoparse When parsing, you'll want to use the flag to include source code info. This will preserve a little more comment info than descriptor produced by protoc. FWIW, the descriptor with source info can be had from protoc with an invocation like so: protoc -o outputfile --include_source_info --include_imports some.proto Once the files are parsed, you can easily recursively visit all of the fields and modify the field descriptors to add a default value. https://godoc.org/github.com/jhump/protoreflect/desc/protoprint Once the option is added, you can write the modified descriptors back to source files with this package. This will preserve a lot of comment info (though admittedly not all). The main downside is that this in no way preserves formatting from the original file. The formatting produced isn't bad, but it doesn't quite look like hand-written code due to the extra whitespace you'll see (blank line between every element). To preserve formatting, you probably will need to write a custom parser. YMMV ---- *Josh Humphries* [email protected] On Fri, May 4, 2018 at 3:04 PM, Mark Hoffman <[email protected]> wrote: > Hi, > > I have the tasks of retrofitting a large repo of .proto files to include a > field option with a default value to every field, except for enums. We > can't assume if the field option is not present that it has a default, for > security reasons. Before I go off an write a parser to handle this one time > task, I was justing wondering something might already exist. One other > issue, I need to preserve the comments in the .proto files. > > Thanks. > > > -- > You received this message because you are subscribed to the Google Groups > "Protocol Buffers" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > Visit this group at https://groups.google.com/group/protobuf. > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "Protocol Buffers" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/protobuf. For more options, visit https://groups.google.com/d/optout.
