gogenerate

package
v0.0.0-...-389821e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 26, 2018 License: BSD-3-Clause, MIT Imports: 10 Imported by: 0

README

myitcv.io/gogenerate

go get -u myitcv.io/gogenerate

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.

See the godoc's

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

View Source
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

View Source
const (
	// FlagLog is the name of the common flag shared between go generate generators
	// to control logging verbosity.
	FlagLog = "gglog"

	// FlagOutPkgPrefix is the prefix used for flags generated by OutPkgFlag.
	FlagOutPkgPrefix = "outpkg:"

	// 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

func CommentLicenseHeader(file *string) (string, error)

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

func DefaultLogLevel(f *string, ll LogLevel)

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

func DirFunc(pkg string, dir, file string, f func(line int, dirArgs []string) error) error

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

func FileGeneratedBy(path string, cmd string) bool

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

func FileIsGenerated(path string) (string, bool)

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

func FilesContainingCmd(dir string, command string) (map[string]int, error)

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). 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

func NameFile(name string, cmd string) string

NameFile returns a file name that conforms with the pattern associated with files generated by the provided command

func NameFileFromFile

func NameFileFromFile(name string, cmd string) (string, bool)

NameFileFromFile uses the provided filename as a template and returns a generated filename consistent with the provided command

func NameTestFile

func NameTestFile(name string, cmd string) string

NameTestFile returns a file name that conforms with the pattern associated with files generated by the provided command

func OutPkgFlag

func OutPkgFlag(key string) *outputs

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.

Types

type LogLevel

type LogLevel string
const (
	LogInfo    LogLevel = "info"
	LogWarning LogLevel = "warning"
	LogError   LogLevel = "error"
	LogFatal   LogLevel = "fatal"
)

The various log levels supported by the flag returned by LogFlag()

Directories

Path Synopsis
_testFiles

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL