Protobuf: protoc-gen-go: print help when invoked directly

Created on 13 Oct 2016  路  9Comments  路  Source: golang/protobuf

Flags such as -M and --plugins聽seem to be entirely undocumented. I expected to find them here or at least be able to run protoc-gen-go --help.

documentation

Most helpful comment

When a person encounters a binary that they know nothing about, it's pretty customary to simply invoke the --help flag and expect something useful (even if all it does it link to the README page).

Thus, perhaps calling protoc-gen-go --help should print the help and exit.

All 9 comments

Finally found them buried in this section.

+1 to this. The use of nested flags to set values with plugins such as:
protoc --go_out=plugins=grpc,import_path=mypackage:. *.proto
is rather confusing.

From what I understand, --go_out is a flag that tells protoc to use the protoc-gen-go plugin to compile a proto to golang. Since the protoc-gen-go plugin isn't being called directly it needs to get flags passed in as nested flags. In this case, it's like calling protoc-gen-go with the flags:
--plugins=grpc --import_path=mypackage

The flags are parsed in protoc-gen-go/generator/generator.go

these nested flags are unfortunate. They raise the learning curve needlessly.

Perhaps this project could consider the "subargs" strategy used by Browserify. It would look something like this:

protoc --go_out [ --plugins=grpc --import_path=mypackage:.* ] *.proto

In other words, whatever is inside the brackets are simply normal flags, but they only apply to go_out.

I totally agree, I've been going round endlessly.

The nested flags are unfortunate, but follow the convention for other protoc output modes. Consistency is better than inventing our own thing here.

They're all documented in README.md, FWIW:
https://github.com/golang/protobuf#parameters

Having protoc-gen-go print something when invoked directly seems reasonable, although I'm not certain how to detect when that's happened short of vendoring in something like https://github.com/mattn/go-isatty.

When a person encounters a binary that they know nothing about, it's pretty customary to simply invoke the --help flag and expect something useful (even if all it does it link to the README page).

Thus, perhaps calling protoc-gen-go --help should print the help and exit.

This is fixed in the v1.20.0 release.

@dsnet could you please confirm what was fixed as part of this or if the steps for checking help is different from what's described above ?

I'm basically trying to list all supported options (more specifically usage of M flag) but this didn't work !

# curl -LkO https://github.com/protocolbuffers/protobuf-go/releases/download/v1.20.0/protoc-gen-go.v1.20.0.linux.amd64.tar.gz
# tar xzvf protoc-gen-go.v1.20.0.linux.amd64.tar.gz
# ./protoc-gen-go --help
protoc-gen-go: unknown argument "--help" (this program should be run by protoc, not directly)
Was this page helpful?
0 / 5 - 0 ratings