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