Skip to content

Commit

Permalink
generator: fix flags.Var usage for ObjectSet
Browse files Browse the repository at this point in the history
Signed-off-by: Vicent Marti <[email protected]>
  • Loading branch information
vmg committed Oct 3, 2023
1 parent d49cd97 commit 91b0b3f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
3 changes: 2 additions & 1 deletion cmd/protoc-gen-go-vtproto/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ import (
func main() {
var cfg generator.Config
var features string

var f flag.FlagSet

f.BoolVar(&cfg.AllowEmpty, "allow-empty", false, "allow generation of empty files")
cfg.Poolable = make(generator.ObjectSet)
f.Var(&cfg.Poolable, "pool", "use memory pooling for this object")
f.BoolVar(&cfg.Wrap, "wrap", false, "generate wrapper types")
f.BoolVar(&cfg.WellKnownTypes, "wkt", true, "generate optimized code for well-known types")
Expand Down
11 changes: 4 additions & 7 deletions generator/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ type featureHelpers struct {

type ObjectSet map[protogen.GoIdent]bool

func (o *ObjectSet) String() string {
return fmt.Sprintf("%#v", *o)
func (o ObjectSet) String() string {
return fmt.Sprintf("%#v", o)
}

func (o *ObjectSet) Set(s string) error {
func (o ObjectSet) Set(s string) error {
idx := strings.LastIndexByte(s, '.')
if idx < 0 {
return fmt.Errorf("invalid object name: %q", s)
Expand All @@ -37,10 +37,7 @@ func (o *ObjectSet) Set(s string) error {
GoName: s[idx+1:],
}

if o == nil {
*o = make(ObjectSet)
}
(*o)[ident] = true
o[ident] = true
return nil
}

Expand Down

0 comments on commit 91b0b3f

Please sign in to comment.