...
1
2
3
4
5
6
7
8
9
10 package main
11
12 import (
13 "errors"
14 "flag"
15 "fmt"
16 "os"
17 "path/filepath"
18
19 gengo "google.golang.org/protobuf/cmd/protoc-gen-go/internal_gengo"
20 "google.golang.org/protobuf/compiler/protogen"
21 "google.golang.org/protobuf/internal/version"
22 )
23
24 const genGoDocURL = "https://protobuf.dev/reference/go/go-generated"
25 const grpcDocURL = "https://grpc.io/docs/languages/go/quickstart/#regenerate-grpc-code"
26
27 func main() {
28 if len(os.Args) == 2 && os.Args[1] == "--version" {
29 fmt.Fprintf(os.Stdout, "%v %v\n", filepath.Base(os.Args[0]), version.String())
30 os.Exit(0)
31 }
32 if len(os.Args) == 2 && os.Args[1] == "--help" {
33 fmt.Fprintf(os.Stdout, "See "+genGoDocURL+" for usage information.\n")
34 os.Exit(0)
35 }
36
37 var (
38 flags flag.FlagSet
39 plugins = flags.String("plugins", "", "deprecated option")
40 )
41 protogen.Options{
42 ParamFunc: flags.Set,
43 }.Run(func(gen *protogen.Plugin) error {
44 if *plugins != "" {
45 return errors.New("protoc-gen-go: plugins are not supported; use 'protoc --go-grpc_out=...' to generate gRPC\n\n" +
46 "See " + grpcDocURL + " for more information.")
47 }
48 for _, f := range gen.Files {
49 if f.Generate {
50 gengo.GenerateFile(gen, f)
51 }
52 }
53 gen.SupportedFeatures = gengo.SupportedFeatures
54 return nil
55 })
56 }
57
View as plain text