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 AnyFileGeneratedBy(path string, cmd string) bool
- func AnyFileIsGenerated(path string) (string, string, bool)
- func CommentLicenseHeader(file *string) (string, error)
- func DefaultLogLevel(f *string, ll LogLevel)
- func DirFunc(pkg string, dir, file string, f func(line int, dirArgs []string) error) error
- func DirFuncFunc(pkg string, dir, file string, hasDirPrefix func([]byte) (string, bool), ...) error
- func FileGeneratedBy(path string, cmd string) bool
- func FileIsGenerated(path string) (string, bool)
- func FilesContainingCmd(dir string, command string, tags map[string]bool) (map[string]int, error)
- func LicenseFileFlag(fs *flag.FlagSet) *string
- func LogFlag(fs *flag.FlagSet) *string
- func NameFile(name string, cmd string) string
- func NameFileFromFile(name string, cmd string) (string, bool)
- func NameTestFile(name string, cmd string) string
- func OutPkgFlag(key string, fs *flag.FlagSet) *outputs
- 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" // FlagOutDirPrefix is the prefix used for flags that indicate an output // directory for a generator FlagOutDirPrefix = "outdir:" // FlagInFilesPrefix is the prefix used for flags that indicate a glob // pattern of input files for a generator FlagInFilesPrefix = "infiles:" // 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 AnyFileGeneratedBy ¶
AnyFileGeneratedBy returns true if the base name of the supplied path is a file that would have been generated by the supplied cmd. Unlike FileGeneratedBy this is not limited to .go files. The extension of the file is also returned
func AnyFileIsGenerated ¶
AnyFileIsGenerated determines wheter the file located at path is generated or not and if it is generated returns the base name of the generator that generated it and the file extension
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 gogenerate.
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 DirFuncFunc ¶
func DirFuncFunc(pkg string, dir, file string, hasDirPrefix func([]byte) (string, bool), f func(prefix string, line int, dirArgs []string) error) error
DirFuncFunc runs f(cmds) on each go generate directive identified by hasDirPrefix found in the absolute-named file that is part of package pkg. Note, you will likely want hasDirPrefix to distinguish between potentially ambiguous directives that share a common prefix. This is typically done by ensuring that the prefix is followed by some whitespace. The prefix returned in the callback to f will be the result of strings.TrimSpace.
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 map of Go file name (defined by go list as GoFiles + CgoFiles + TestGoFiles + XTestGoFiles) in the directory dir, to a count of the number of times directive command appears in that file (after quote and variable expansion as described by go generate -help). Commands can be gobin commands or plain PATH-based command calls. When comparing PATH-based commands, the filepath.Base of each is compared. The file names will, by definition, be relative to dir
func LicenseFileFlag ¶
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 ¶
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 OutPkgFlag ¶
OutPkgFlag defines a new flag "outpkg:"+key that can accept a list of package specifications that represent output targets above and beyond the default of self.