func (a *app) parseArgs(fs *flag.FlagSet, args []string) error { fs.SetOutput(a.out) fs.Usage = func() { fmt.Fprintf(a.out, help, args[0], args[0]) fs.PrintDefaults() } fs.Var(&a.typeNames, "type", "A generated proto.Message type to generate stubs for (required, repeatable)") fs.StringVar(&a.outFile, "out", "proto_gae.gen.go", "The name of the output file") fs.StringVar(&a.header, "header", copyright, "Header text to put at the top of "+ "the generated file. Defaults to the Chromium Authors copyright.") if err := fs.Parse(args[1:]); err != nil { return err } fail := errors.MultiError(nil) if a.typeNames.Data == nil || a.typeNames.Data.Len() == 0 { fail = append(fail, errors.New("must specify one or more -type")) } if !strings.HasSuffix(a.outFile, ".go") { fail = append(fail, errors.New("-output must end with '.go'")) } if len(fail) > 0 { for _, e := range fail { fmt.Fprintln(a.out, "error:", e) } fmt.Fprintln(a.out) fs.Usage() return fail } return nil }
func (p *structPLS) Load(propMap PropertyMap) error { if err := p.Problem(); err != nil { return err } convFailures := errors.MultiError(nil) t := reflect.Type(nil) for name, props := range propMap { multiple := len(props) > 1 for i, prop := range props { if reason := loadInner(p.c, p.o, i, name, prop, multiple); reason != "" { if t == nil { t = p.o.Type() } convFailures = append(convFailures, &ErrFieldMismatch{ StructType: t, FieldName: name, Reason: reason, }) } } } if len(convFailures) > 0 { return convFailures } return nil }
func (p *structPLS) Load(propMap PropertyMap) error { convFailures := errors.MultiError(nil) useExtra := false extra := (*PropertyMap)(nil) if i, ok := p.c.bySpecial["extra"]; ok { useExtra = true f := p.c.byIndex[i] if f.canSet { extra = p.o.Field(i).Addr().Interface().(*PropertyMap) } } t := reflect.Type(nil) for name, props := range propMap { multiple := len(props) > 1 for i, prop := range props { if reason := loadInner(p.c, p.o, i, name, prop, multiple); reason != "" { if useExtra { if extra != nil { if *extra == nil { *extra = make(PropertyMap, 1) } (*extra)[name] = props } break // go to the next property in propMap } else { if t == nil { t = p.o.Type() } convFailures = append(convFailures, &ErrFieldMismatch{ StructType: t, FieldName: name, Reason: reason, }) } } } } if len(convFailures) > 0 { return convFailures } return nil }