pseudomuto / protoc-gen-doc

Documentation generator plugin for Google Protocol Buffers
MIT License
2.67k stars 464 forks source link

Unknown flag: --doc_opt #322

Open ben-skyportsystems opened 7 years ago

ben-skyportsystems commented 7 years ago

Hi,

I'm trying to use your plugin and can't get it to accept the '--doc_opt' flag. From what I can tell, protoc parses flags as "--foo_arg" and sends "arg" to the plugin "foo", at least that's what I see in other plugins we use (notably protoc-gen-go)

ben@ben-lab-sc1:~/src/github.com/pseudomuto/protoc-gen-doc/examples$ protoc --doc_out=doc --doc_opt=html,myoutput.html proto/Customer.proto 
Unknown flag: --doc_opt
ben@ben-lab-sc1:~/src/github.com/pseudomuto/protoc-gen-doc/examples$ protoc --version
libprotoc 3.0.0
ben@ben-lab-sc1:~/src/github.com/pseudomuto/protoc-gen-doc/examples$ go version
go version go1.8.3 linux/amd64
ben@ben-lab-sc1:~/src/github.com/pseudomuto/protoc-gen-doc/examples$ which protoc-gen-doc
/home/ben/bin/protoc-gen-doc
ben@ben-lab-sc1:~src/github.com/pseudomuto/protoc-gen-doc/examples$ echo $GOPATH
/home/ben

I built the tool as follows:

ben@ben-lab-sc1:~/src/github.com/pseudomuto/protoc-gen-doc/cmd/protoc-gen-doc$ go install -v
github.com/pseudomuto/protoc-gen-doc/cmd/protoc-gen-doc

Are there any steps that I missed in order to enable this flag?

thanks, Ben

har07 commented 7 years ago

The exact same error also happened to me. Somebody suggested, in a different protoc plugin issue, to explicitly set --plugin flag as workaround and it seemed to work well for their case, but it didn't work for me when I tried for this protoc-gen-doc case (still return Unknown flag error).

SPSpwetter commented 7 years ago

What version of protoc are you on?

har07 commented 7 years ago

@SPSpwetter this is mine :

$ protoc --version
libprotoc 3.1.0
har07 commented 7 years ago

Upgraded to 3.4.0 and now it seems to work (without --plugin flag), only my custom template still has errors. Thanks!!

SPSpwetter commented 7 years ago

Yeah, I thought that might be it. We're on 3.0.0 so we have the same problem. We can generate the non-html off line though until we go all the way to 3.4.

pseudomuto commented 7 years ago

Seems like this works from 3.3.0 forward. If you're unable to bump the protoc version, you could always use the docker container to generate docs.

Does this work for you?

docker run --rm \
  -v $(pwd)/doc:/out \
  -v $(pwd)/proto:/protos \
  pseudomuto/protoc-gen-doc --doc_opt=html,myoutput.html /protos/Customer.proto
ben-skyportsystems commented 7 years ago

Thanks for responding @pseudomuto. We have a bunch of tooling around protoc, so I'm really not able to use the docker solution. Moving protobufs forward would also be a big change that I'm not sure I can bite off at this time. Can you tell me more about what changes in Protobuf 3.3 make this work? Also, what version dependencies do you have on protoc-gen-go, which this seems to piggy-back on top of? Thanks!

brnhffmnn commented 7 years ago

I'm trying to get v1.0.0 working together with google/protobuf-gradle-plugin and are struggling also with --doc_opt.

Apparently, protoc allows custom options to be passed to the *_out flag. In turn, the gradle plugin specifically allows to pass custom plugin options to this flag only. See how they are setting up options for the protoc invokation: GenerateProtoTask.groovy#L324-L328.

Would it be possible to support options prepended to the output argument? Maybe additionally to the --doc_opt flag?

brnhffmnn commented 7 years ago

As I just learnt from google/protobuf-gradle-plugin#184 options can also be passed using the older way of by prepending them to the _out flag. Accordingly, --doc_out=doc --doc_opt=html,myoutput.html is equivalent to --doc_out=html,myoutput.html:doc.