// NAME // generate-objects - Generate net/artproto/gen_objects.go // // DESCRIPTION // Generates trivial setter methods and constants for the object types // defined in net/artproto/objects. // // OPTIONS // --nogofmt // do not process the generated code through gofmt func TaskGenerateObjects(t *tasking.T) { var w io.WriteCloser w, err := os.Create(filepath.Join("net", "artproto", "gen_objects.go")) if err != nil { t.Fatal(err) } if !t.Flags.Bool("nogofmt") { if gofmt, err := codegen.NewGofmtWriteCloser(w); err != nil { w.Close() t.Fatal(err) } else { w = gofmt } } defer w.Close() cw := &CodeWriter{W: w} cw.Printf(`// GENERATED CODE - DO NOT EDIT. // This code is generated with the following command: // // gotask generate-objects `) cw.Printf("package artproto\n") for _, typeID := range artproto.ObjTypeIDs { if err := generateForObject(cw, typeID); err != nil { t.Fatal(err) } } if cw.Err != nil { t.Fatal(cw.Err) } }
func (dcp *DCP) writePackage(outDir string, useGofmt bool) error { packageDirname := filepath.Join(outDir, dcp.Metadata.Name) err := os.MkdirAll(packageDirname, os.ModePerm) if err != nil && !os.IsExist(err) { return err } packageFilename := filepath.Join(packageDirname, dcp.Metadata.Name+".go") packageFile, err := os.Create(packageFilename) if err != nil { return err } var output io.WriteCloser = packageFile if useGofmt { if output, err = codegen.NewGofmtWriteCloser(output); err != nil { packageFile.Close() return err } } if err = packageTmpl.Execute(output, dcp); err != nil { output.Close() return err } return output.Close() }