Explorar o código

protogen: produce an error if len(os.Args) > 1

Users sometimes run protoc-gen-go directly (rather than via protoc
--go_out) and are then confused when it sits and does nothing,
waiting for input from stdin. Print an error if any command-line
arguments are passed to it.

Change-Id: I10a059a82ec71b61c4eb6aeecc1e47e2446feabb
Reviewed-on: https://go-review.googlesource.com/c/139877
Reviewed-by: Joe Tsai <thebrokentoaster@gmail.com>
Damien Neil %!s(int64=7) %!d(string=hai) anos
pai
achega
d277b5236a
Modificáronse 1 ficheiros con 3 adicións e 0 borrados
  1. 3 0
      protogen/protogen.go

+ 3 - 0
protogen/protogen.go

@@ -52,6 +52,9 @@ func Run(opts *Options, f func(*Plugin) error) {
 }
 
 func run(opts *Options, f func(*Plugin) error) error {
+	if len(os.Args) > 1 {
+		return fmt.Errorf("unknown argument %q (this program should be run by protoc, not directly)", os.Args[1])
+	}
 	in, err := ioutil.ReadAll(os.Stdin)
 	if err != nil {
 		return err