1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
20 if len(os.Args) == 2 && os.Args[1] == "-check" {
22 } else if len(os.Args) != 1 {
23 panic("usage: go run generate.go [-check]")
26 in, err := os.Open("list.go")
30 buf, err := ioutil.ReadAll(in)
34 orig := regexp.MustCompile(`(?ms)\nfunc [^\n]*generated_CollectionList\(.*?\n}\n`).Find(buf)
36 panic("can't find CollectionList func")
39 outfile, err := os.OpenFile("generated.go~", os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0777)
44 gofmt := exec.Command("goimports")
45 gofmt.Stdout = outfile
46 gofmt.Stderr = os.Stderr
47 out, err := gofmt.StdinPipe()
53 out.Write(regexp.MustCompile(`(?ms)^.*package .*?import.*?\n\)\n`).Find(buf))
54 io.WriteString(out, "//\n// -- this file is auto-generated -- do not edit -- edit list.go and run \"go generate\" instead --\n//\n\n")
55 for _, t := range []string{"Container", "Specimen", "User"} {
56 _, err := out.Write(bytes.ReplaceAll(orig, []byte("Collection"), []byte(t)))
71 diff := exec.Command("diff", "-u", "/dev/fd/3", "/dev/fd/4")
72 for _, fnm := range []string{"generated.go", "generated.go~"} {
73 f, err := os.Open(fnm)
78 diff.ExtraFiles = append(diff.ExtraFiles, f)
80 diff.Stdout = os.Stdout
81 diff.Stderr = os.Stderr
87 err = os.Rename("generated.go~", "generated.go")