func generateBootstrap(noDot bool) { packageName := getPackage() formattedPackage := strings.Replace(strings.Title(strings.Replace(packageName, "_", " ", -1)), " ", "", -1) data := bootstrapData{ Package: packageName, FormattedPackage: formattedPackage, GinkgoImport: `. "github.com/onsi/ginkgo"`, GomegaImport: `. "github.com/onsi/gomega"`, } if noDot { data.GinkgoImport = `"github.com/onsi/ginkgo"` data.GomegaImport = `"github.com/onsi/gomega"` } targetFile := fmt.Sprintf("%s_suite_test.go", packageName) if fileExists(targetFile) { fmt.Printf("%s already exists.\n\n", targetFile) os.Exit(1) } else { fmt.Printf("Generating ginkgo test suite bootstrap for %s in:\n\t%s\n", packageName, targetFile) } f, err := os.Create(targetFile) if err != nil { complainAndQuit("Could not create file: " + err.Error()) panic(err.Error()) } defer f.Close() bootstrapTemplate, err := template.New("bootstrap").Parse(bootstrapText) if err != nil { panic(err.Error()) } buf := &bytes.Buffer{} bootstrapTemplate.Execute(buf, data) if noDot { contents, err := nodot.ApplyNoDot(buf.Bytes()) if err != nil { complainAndQuit("Failed to import nodot declarations: " + err.Error()) } fmt.Println("To update the nodot declarations in the future, switch to this directory and run:\n\tginkgo nodot") buf = bytes.NewBuffer(contents) } buf.WriteTo(f) goFmt(targetFile) }
func updateNodot(args []string, additionalArgs []string) { suiteFile, perm := findSuiteFile() data, err := ioutil.ReadFile(suiteFile) if err != nil { complainAndQuit("Failed to update nodot declarations: " + err.Error()) } content, err := nodot.ApplyNoDot(data) if err != nil { complainAndQuit("Failed to update nodot declarations: " + err.Error()) } ioutil.WriteFile(suiteFile, content, perm) goFmt(suiteFile) }