Documentation ¶
Overview ¶
Package gogenerate exposes some of the unexported internals of the go generate command as a convenience for the authors of go generate generators. See https://github.com/myitcv/gogenerate/wiki/Go-Generate-Notes for further notes on such generators. It also exposes some convenience functions that might be useful to authors of generators
Index ¶
- Constants
- func CommentLicenseHeader(file *string) (string, error)
- func DefaultLogLevel(f *string, ll LogLevel)
- func DirFunc(pkg string, name string, f func(line int, dirArgs []string) error) error
- func FileGeneratedBy(path string, cmd string) bool
- func FileIsGenerated(path string) (string, bool)
- func FilesContainingCmd(dir string, commands ...string) ([]string, error)
- func LicenseFileFlag() *string
- func LogFlag() *string
- func NameFile(name string, cmd string) string
- func NameFileFromFile(name string, cmd string) (string, bool)
- func NameTestFile(name string, cmd string) string
- func WriteIfDiff(toWrite []byte, path string) (bool, error)
- type LogLevel
Constants ¶
const ( GOARCH = "GOARCH" GOFILE = "GOFILE" GOLINE = "GOLINE" GOOS = "GOOS" GOPACKAGE = "GOPACKAGE" GOPATH = "GOPATH" GoGeneratePrefix = "//go:generate" )
These constants correspond in name and value to the details given in go generate --help
const ( // FlagLog is the name of the common flag shared between go generate generators // to control logging verbosity FlagLog = "gglog" // FlagLicenseFile is the name of the common flag shared between go generate generators // to provide a license header file FlagLicenseFile = "licenseFile" )
Variables ¶
This section is empty.
Functions ¶
func CommentLicenseHeader ¶
CommentLicenseHeader is a convenience function to be used in conjunction with LicenseFileFlag; if a filename is provided it reads the contents of the file and returns a line-commented transformation of the contents with a final blank newline
func DefaultLogLevel ¶
DefaultLogLevel is provided simply as a convenience along with LogFlag to ensure a default LogLevel in a flag variable. This is necessary because of the interplay between go generate argument parsing and the advice given for log levels via gg.
func DirFunc ¶
DirFunc runs f(cmds) on each go generate directive (as defined by go generate -help) found in the absolute-named file that is part of package pkg
func FileGeneratedBy ¶
FileGeneratedBy returns true if the base name of the supplied path is a Go file that would have been generated by the supplied cmd
func FileIsGenerated ¶
FileIsGenerated determines wheter the Go file located at path is generated or not and if it is generated returns the base name of the generator that generated it
func FilesContainingCmd ¶
FilesContainingCmd returns a sorted list of Go file names (defined by go list as GoFiles + CgoFiles + TestGoFiles + XTestGoFiles) in the directory dir that contain a command matching any of the provided commands after quote and variable expansion (as described by go generate -help). When comparing commands, the filepath.Base of each is compared. The file names will, by definition, be relative to dir
func LicenseFileFlag ¶
func LicenseFileFlag() *string
LicenseFileFlag defines a command line string flag named according to the constant FlagLicenseFile and returns a pointer ot the string that flag set
func LogFlag ¶
func LogFlag() *string
LogFlag defines a command line string flag named according to the constant FlagLog and returns a pointer to the string the flag sets
func NameFile ¶
NameFile returns a file name that conforms with the pattern associated with files generated by the provided command
func NameFileFromFile ¶
NameFileFromFile uses the provided filename as a template and returns a generated filename consistent with the provided command
func NameTestFile ¶
NameTestFile returns a file name that conforms with the pattern associated with files generated by the provided command
func WriteIfDiff ¶
WriteIfDiff writes the supplied byte slice to the file identified by path in the case that either no file exists at that path or the contents of the file differ from the supplied bytes. The returned bool indicates whether a write was necessary or not; in case of any errors false is returned along with the error