Documentation
¶
Overview ¶
Package genny is a _framework_ for writing modular generators, it however, doesn't actually generate anything. It just makes it easier for you to. :)
Index ¶
- Constants
- Variables
- func Confirm(msg string) bool
- func ForceBox(g *Generator, box packd.Walker, force bool) error
- func GoBin() string
- func HasExt(f File, ext ...string) bool
- type DeleteFn
- type Dir
- type Disk
- type File
- type Generator
- func (g *Generator) Box(box packd.Walker) error
- func (g *Generator) Command(cmd *exec.Cmd)
- func (g *Generator) Event(kind string, payload mapi.Mapi)
- func (g *Generator) File(f File)
- func (g1 *Generator) Merge(g2 *Generator)
- func (g *Generator) RunFn(fn RunFn)
- func (g *Generator) Transform(f File) (File, error)
- func (g *Generator) Transformer(t Transformer)
- type Group
- type Logger
- type RequestResult
- type Results
- type RunFn
- type Runner
- func (r *Runner) Chdir(path string, fn func() error) error
- func (r *Runner) Delete(path string) error
- func (r *Runner) Exec(cmd *exec.Cmd) error
- func (r *Runner) File(f File) error
- func (r *Runner) FindFile(name string) (File, error)
- func (r *Runner) FindStep(name string) (*Step, error)
- func (r *Runner) LookPath(s string) (string, error)
- func (r *Runner) ReplaceStep(name string, s *Step) error
- func (r *Runner) Request(req *http.Request) (*http.Response, error)
- func (r *Runner) RequestWithClient(req *http.Request, c *http.Client) (*http.Response, error)
- func (r *Runner) Results() Results
- func (r *Runner) Run() error
- func (r *Runner) Steps() []*Step
- func (r *Runner) With(g *Generator) error
- func (r *Runner) WithFn(fn func() (*Generator, error)) error
- func (r *Runner) WithGroup(gg *Group)
- func (r *Runner) WithNew(g *Generator, err error) error
- func (r *Runner) WithRun(fn RunFn)
- func (r *Runner) WithStep(name string, step *Step) error
- type Step
- type Transformer
- type TransformerFn
Examples ¶
Constants ¶
const ( EvtStarted = "genny:runner:started" EvtFinished = "genny:runner:finished" EvtFinishedErr = "genny:runner:finished:err" EvtStepPrefix = "genny:step" )
Events have been deprecated. Please manually trigger events if needed.
const Version = "v0.2.0"
Variables ¶
var DefaultLogLvl = logger.InfoLevel
Functions ¶
Types ¶
type Disk ¶
type Disk struct { Runner *Runner // contains filtered or unexported fields }
Disk is a virtual file system that works with both dry and wet runners. Perfect for seeding Files or non-destructively deleting files
type File ¶
type File = packd.SimpleFile
File interface for working with files
type Generator ¶
type Generator struct { StepName string Should func(*Runner) bool Root string ErrorFn func(error) // contains filtered or unexported fields }
Generator is the basic type for generators to use
Example (WithCommand) ¶
package main import ( "context" "fmt" "go/build" "log" "os/exec" "strings" "github.com/gobuffalo/genny" "github.com/gobuffalo/genny/gentest" ) // exampleLogger just cleans up variable log content // such as GOPATH, step names, etc.... // without this Go Example tests won't work. func exampleLogger(l *gentest.Logger) genny.Logger { l.CloseFn = func() error { s := l.Stream.String() c := build.Default for _, src := range c.SrcDirs() { s = strings.Replace(s, src, "/go/src", -1) } s = strings.Replace(s, "\\", "/", -1) for i, line := range strings.Split(s, "\n") { if strings.Contains(line, "Step:") { s = strings.Replace(s, line, fmt.Sprintf("[DEBU] Step: %d", i+1), 1) } } fmt.Print(s) return nil } return l } func main() { // create a new `*genny.Generator` g := genny.New() g.Command(exec.Command("go", "version")) // create a new `*genny.Runner` r := genny.NewRunner(context.Background()) // add a new logger to clean and dump output // for the example tests r.Logger = exampleLogger(gentest.NewLogger()) // add the generator to the `*genny.Runner`. r.With(g) // run the runner if err := r.Run(); err != nil { log.Fatal(err) } }
Output: [DEBU] Step: 1 [DEBU] Chdir: /go/src/github.com/gobuffalo/genny [DEBU] Exec: go version
Example (WithFile) ¶
package main import ( "context" "fmt" "go/build" "log" "strings" "github.com/gobuffalo/genny" "github.com/gobuffalo/genny/gentest" ) // exampleLogger just cleans up variable log content // such as GOPATH, step names, etc.... // without this Go Example tests won't work. func exampleLogger(l *gentest.Logger) genny.Logger { l.CloseFn = func() error { s := l.Stream.String() c := build.Default for _, src := range c.SrcDirs() { s = strings.Replace(s, src, "/go/src", -1) } s = strings.Replace(s, "\\", "/", -1) for i, line := range strings.Split(s, "\n") { if strings.Contains(line, "Step:") { s = strings.Replace(s, line, fmt.Sprintf("[DEBU] Step: %d", i+1), 1) } } fmt.Print(s) return nil } return l } func main() { // create a new `*genny.Generator` g := genny.New() // add a file named `index.html` that has a body of `Hello\n` // to the generator g.File(genny.NewFileS("index.html", "Hello\n")) // create a new `*genny.Runner` r := genny.NewRunner(context.Background()) // add a new logger to clean and dump output // for the example tests r.Logger = exampleLogger(gentest.NewLogger()) // add the generator to the `*genny.Runner`. r.With(g) // run the runner if err := r.Run(); err != nil { log.Fatal(err) } }
Output: [DEBU] Step: 1 [DEBU] Chdir: /go/src/github.com/gobuffalo/genny [DEBU] File: /go/src/github.com/gobuffalo/genny/index.html
func (*Generator) Transformer ¶
func (g *Generator) Transformer(t Transformer)
Transformer adds a file transform to the generator
type Group ¶
type Group struct { Generators []*Generator // contains filtered or unexported fields }
type RequestResult ¶
type Runner ¶
type Runner struct { Logger Logger // Logger to use for the run Context context.Context // context to use for the run ExecFn func(*exec.Cmd) error // function to use when executing files FileFn func(File) (File, error) // function to use when writing files ChdirFn func(string, func() error) error // function to use when changing directories DeleteFn func(string) error // function used to delete files/folders RequestFn func(*http.Request, *http.Client) (*http.Response, error) // function used to make http requests LookPathFn func(string) (string, error) // function used to make exec.LookPath lookups Root string // the root of the write path Disk *Disk // contains filtered or unexported fields }
Runner will run the generators
Example ¶
package main import ( "context" "fmt" "go/build" "log" "strings" "github.com/gobuffalo/genny" "github.com/gobuffalo/genny/gentest" ) // exampleLogger just cleans up variable log content // such as GOPATH, step names, etc.... // without this Go Example tests won't work. func exampleLogger(l *gentest.Logger) genny.Logger { l.CloseFn = func() error { s := l.Stream.String() c := build.Default for _, src := range c.SrcDirs() { s = strings.Replace(s, src, "/go/src", -1) } s = strings.Replace(s, "\\", "/", -1) for i, line := range strings.Split(s, "\n") { if strings.Contains(line, "Step:") { s = strings.Replace(s, line, fmt.Sprintf("[DEBU] Step: %d", i+1), 1) } } fmt.Print(s) return nil } return l } func main() { // create a new `*genny.Runner` r := genny.NewRunner(context.Background()) // add a new logger to clean and dump output // for the example tests r.Logger = exampleLogger(gentest.NewLogger()) // add the generator(s) to the `*genny.Runner`. // r.With(g) // run the runner if err := r.Run(); err != nil { log.Fatal(err) } }
Output:
func NewRunner ¶
NewRunner will NOT execute commands and write files it is NOT destructive it is just the most basic Runner you can have.
func (*Runner) Chdir ¶
Chdir will change to the specified directory and revert back to the current directory when the runner function has returned. If the directory does not exist, it will be created for you.
func (*Runner) RequestWithClient ¶
func (*Runner) WithFn ¶
WithFn will evaluate the function and if successful it will add the Generator to the Runner, otherwise it will return the error Deprecated
type Transformer ¶
func Dot ¶
func Dot() Transformer
Dot will convert -dot- in a file name to just a . example -dot-travis.yml becomes .travis.yml
func NewTransformer ¶
func NewTransformer(ext string, fn TransformerFn) Transformer
func Replace ¶
func Replace(search string, replace string) Transformer
Replace search/replace in a file name
type TransformerFn ¶
func ForceFile ¶
func ForceFile(f File, force bool) TransformerFn
ForceFile is a TransformerFn that will return an error if the path exists if `force` is false. If `force` is true it will delete the path.
Source Files
¶
Directories
¶
Path | Synopsis |
---|---|
new
You can use the "packr clean" command to clean up this, and any other packr generated files.
|
You can use the "packr clean" command to clean up this, and any other packr generated files. |
internal
|
|
movinglater
|
|
attrs
This package has been moved to github.com/gobuffalo/attrs
|
This package has been moved to github.com/gobuffalo/attrs |
dep
This package has been moved to github.com/gobuffalo/depgen
|
This package has been moved to github.com/gobuffalo/depgen |
git
This package has been moved to github.com/gobuffalo/gitgen
|
This package has been moved to github.com/gobuffalo/gitgen |
gotools/goimports
This package has moved to github.com/gobuffalo/gogen/goimports
|
This package has moved to github.com/gobuffalo/gogen/goimports |
gotools/gomods
This package has moved to github.com/gobuffalo/gogen/gomods
|
This package has moved to github.com/gobuffalo/gogen/gomods |
You can use the "packr2 clean" command to clean up this, and any other packr generated files.
|
You can use the "packr2 clean" command to clean up this, and any other packr generated files. |