Skip to content

Commit

Permalink
Merge pull request #239 from yoheimuta/signal-proto3-optional-support
Browse files Browse the repository at this point in the history
feat: Signal proto3 optional support
yoheimuta authored May 3, 2022
2 parents 984f035 + 5defbf6 commit bdd2093
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions internal/cmd/protocgenprotolint/cmd.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
package protocgenprotolint

import (
"bytes"
"fmt"
"io"
"io/ioutil"
"os"
"strings"

"google.golang.org/protobuf/types/pluginpb"

"github.com/yoheimuta/protolint/internal/cmd/subcmds"

"github.com/yoheimuta/protolint/internal/cmd/subcmds/lint"
@@ -36,6 +40,12 @@ func Do(
return doVersion(stdout)
}

err := signalSupportProto3Optional()
if err != nil {
_, _ = fmt.Fprintln(stderr, err)
return osutil.ExitInternalFailure
}

subCmd, err := newSubCmd(stdin, stdout, stderr)
if err != nil {
_, _ = fmt.Fprintln(stderr, err)
@@ -44,6 +54,24 @@ func Do(
return subCmd.Run()
}

func signalSupportProto3Optional() error {
// supports proto3 field presence
// See https://github.com/protocolbuffers/protobuf/blob/cdc11c2d2d314ce0382fe0eaa715e5e0e1270438/docs/implementing_proto3_presence.md#signaling-that-your-code-generator-supports-proto3-optional
var supportedFeatures = uint64(pluginpb.CodeGeneratorResponse_FEATURE_PROTO3_OPTIONAL)
data, err := proto.Marshal(&protogen.CodeGeneratorResponse{
SupportedFeatures: &supportedFeatures,
})
if err != nil {
return err
}

_, err = io.Copy(os.Stdout, bytes.NewReader(data))
if err != nil {
return err
}
return nil
}

func newSubCmd(
stdin io.Reader,
stdout io.Writer,

0 comments on commit bdd2093

Please sign in to comment.