<commit_before>// Copyright 2018 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// The genv command generates version-specific go command source files.
package main

import (
	"bytes"
	"fmt"
	"html/template"
	"io"
	"os"
	"path/filepath"
	"time"
)

func usage() {
	fmt.Fprintln(os.Stderr, "usage: genv <version>...")
	os.Exit(2)
}

func main() {
	if len(os.Args) == 1 {
		usage()
	}
	for _, version := range os.Args[1:] {
		var buf bytes.Buffer
		if err := mainTmpl.Execute(&buf, struct {
			Year    int
			Version string
		}{time.Now().Year(), version}); err != nil {
			failf("mainTmpl.execute: %v", err)
		}
		path := filepath.Join(os.Getenv("GOPATH"), "src/golang.org/x/build/version", version, version+".go")
		if err := os.Mkdir(filepath.Dir(path), 0755); err != nil {
			failf("os.Mkdir: %v", err)
		}
		f, err := os.Create(path)
		if err != nil {
			failf("os.Create: %v", err)
		}
		defer f.Close()
		if _, err := io.Copy(f, &buf); err != nil {
			failf("could not write to file: %v", err)
		}
	}
}

func failf(format string, args ...interface{}) {
	if len(format) == 0 || format[len(format)-1] != '\n' {
		format += "\n"
	}
	fmt.Fprintf(os.Stderr, format, args...)
	os.Exit(1)
}

var mainTmpl = template.Must(template.New("main").Parse(`// Copyright {{.Year}} The Go Authors. All rights reserved.
	// Use of this source code is governed by a BSD-style
	// license that can be found in the LICENSE file.

	// The {{.Version}} command runs the go command from {{.Version}}.
	//
	// To install, run:
	//
	//     $ go get golang.org/x/build/version/{{.Version}}
	//     $ {{.Version}} download
	//
	// And then use the {{.Version}} command as if it were your normal go
	// command.
	//
	// See the release notes at https://golang.org/doc/{{.Version}}
	//
	// File bugs at https://golang.org/issues/new
	package main

	import "golang.org/x/build/version"

	func main() {
		version.Run("{{.Version}}")
	}
`))<commit_msg>version/internal/genv: gofmt generated file<commit_after>// Copyright 2018 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// The genv command generates version-specific go command source files.
package main

import (
	"bytes"
	"fmt"
	"html/template"
	"io/ioutil"
	"os"
	"os/exec"
	"path/filepath"
	"time"
)

func usage() {
	fmt.Fprintln(os.Stderr, "usage: genv <version>...")
	os.Exit(2)
}

func main() {
	if len(os.Args) == 1 {
		usage()
	}
	for _, version := range os.Args[1:] {
		var buf bytes.Buffer
		if err := mainTmpl.Execute(&buf, struct {
			Year    int
			Version string
		}{time.Now().Year(), version}); err != nil {
			failf("mainTmpl.execute: %v", err)
		}
		path := filepath.Join(os.Getenv("GOPATH"), "src/golang.org/x/build/version", version, version+".go")
		if err := os.Mkdir(filepath.Dir(path), 0755); err != nil {
			failf("os.Mkdir: %v", err)
		}
		if err := ioutil.WriteFile(path, buf.Bytes(), 0666); err != nil {
			failf("ioutil.WriteFile: %v", err)
		}
		fmt.Println("Wrote", path)
		if err := exec.Command("gofmt", "-w", path).Run(); err != nil {
			failf("could not gofmt file %q: %v", path, err)
		}
	}
}

func failf(format string, args ...interface{}) {
	if len(format) == 0 || format[len(format)-1] != '\n' {
		format += "\n"
	}
	fmt.Fprintf(os.Stderr, format, args...)
	os.Exit(1)
}

var mainTmpl = template.Must(template.New("main").Parse(`// Copyright {{.Year}} The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// The {{.Version}} command runs the go command from {{.Version}}.
//
// To install, run:
//
//     $ go get golang.org/x/build/version/{{.Version}}
//     $ {{.Version}} download
//
// And then use the {{.Version}} command as if it were your normal go
// command.
//
// See the release notes at https://golang.org/doc/{{.Version}}
//
// File bugs at https://golang.org/issues/new
package main

import "golang.org/x/build/version"

func main() {
	version.Run("{{.Version}}")
}
`))
{'fraction_non_alphanumeric': 0.18450363196125907, 'fraction_numerical': 0.00774818401937046, 'mean_word_length': 3.0941526263627352, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4913290', 'n_tokens_mistral': 1587, 'n_tokens_neox': 1482, 'n_words': 435}