package genny
import "github.com/gobuffalo/genny"
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
- func (d *Disk) Add(f File)
- func (d *Disk) AddBox(box packd.Walker) error
- func (d *Disk) Delete(name string) error
- func (d *Disk) Files() []File
- func (d *Disk) Find(name string) (File, error)
- func (d *Disk) Remove(name string)
- type File
- func NewDir(path string, perm os.FileMode) File
- func NewFile(name string, r io.Reader) File
- func NewFileB(name string, s []byte) File
- func NewFileS(name string, s string) File
- func StripExt(f File, ext string) File
- type Generator
- func New() *Generator
- func (g *Generator) Box(box packd.Walker) error
- func (g *Generator) Command(cmd *exec.Cmd)
- 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
- func (gg *Group) Add(g *Generator)
- func (gg *Group) Merge(g2 *Group)
- func (gg *Group) With(r *Runner)
- type Logger
- type RequestResult
- type Results
- type RunFn
- type Runner
- func DryRunner(ctx context.Context) *Runner
- func NewRunner(ctx context.Context) *Runner
- func WetRunner(ctx context.Context) *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
- func NewStep(g *Generator, index int) (*Step, error)
- func (s *Step) After(g *Generator) DeleteFn
- func (s *Step) Before(g *Generator) DeleteFn
- func (s *Step) Run(r *Runner) error
- type Transformer
- func Dot() Transformer
- func NewTransformer(ext string, fn TransformerFn) Transformer
- func Replace(search string, replace string) Transformer
- func (t Transformer) Transform(f File) (File, error)
- type TransformerFn
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.
Variables ¶
var Version = ""
Functions ¶
func Confirm ¶
func ForceBox ¶
ForceBox will mount each file in the box and wrap it with ForceFile
func GoBin ¶
func GoBin() string
func HasExt ¶
HasExt checks if a file has ANY of the extensions passed in. If no extensions are given then `true` is returned
Types ¶
type DeleteFn ¶
type DeleteFn func()
type Dir ¶
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
func (*Disk) Add ¶
Add file to the virtual disk
func (*Disk) AddBox ¶
func (*Disk) Delete ¶
Delete calls the Runner#Delete function
func (*Disk) Files ¶
Files returns a sorted list of all the files in the disk
func (*Disk) Find ¶
Find a file from the virtual disk. If the file doesn't exist it will try to read the file from the physical disk.
func (*Disk) Remove ¶
Remove a file(s) from the virtual disk.
type File ¶
type File = packd.SimpleFile
File interface for working with files
func NewDir ¶
func NewFile ¶
NewFile takes the name of the file you want to write to and a reader to reader from
func NewFileB ¶
func NewFileS ¶
func StripExt ¶
StripExt from a File and return a new one
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
func New ¶
func New() *Generator
New, well-formed, generator
func (*Generator) Box ¶
Box walks through a packr.Box and adds Files for each entry in the box.
func (*Generator) Command ¶
Command adds a command to be run when the generator is run
func (*Generator) File ¶
File adds a file to be run when the generator is run
func (*Generator) Merge ¶
func (*Generator) RunFn ¶
RunFn adds a generic "runner" function to the generator.
func (*Generator) Transform ¶
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 }
func (*Group) Add ¶
func (*Group) Merge ¶
func (*Group) With ¶
type Logger ¶
Logger interface for a logger to be used with genny. Logrus is 100% compatible.
type RequestResult ¶
type RequestResult struct { Request *http.Request Response *http.Response Client *http.Client Error error }
type Results ¶
type Results struct { Files []File Commands []*exec.Cmd Requests []RequestResult }
func (Results) Find ¶
type RunFn ¶
func Force ¶
Force is a RunFn that will return an error if the path exists if `force` is false. If `force` is true it will delete the path. Is is recommended to use ForceFile when you can.
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
func DryRunner ¶
DryRunner will NOT execute commands and write files it is NOT destructive
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 WetRunner ¶
WetRunner will execute commands and write files it is DESTRUCTIVE
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) Delete ¶
func (*Runner) Exec ¶
Exec can be used inside of Generators to run commands
func (*Runner) File ¶
File can be used inside of Generators to write files
func (*Runner) FindFile ¶
func (*Runner) FindStep ¶
func (*Runner) LookPath ¶
func (*Runner) ReplaceStep ¶
func (*Runner) Request ¶
func (*Runner) RequestWithClient ¶
func (*Runner) Results ¶
func (*Runner) Run ¶
func (*Runner) Steps ¶
func (*Runner) With ¶
With adds a Generator to the Runner
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
func (*Runner) WithGroup ¶
func (*Runner) WithNew ¶
WithNew takes a Generator and an error. Perfect for new-ing up generators
// foo.New(Options) (*genny.Generator, error) if err := run.WithNew(foo.New(opts)); err != nil { return err }
func (*Runner) WithRun ¶
func (*Runner) WithStep ¶
type Step ¶
type Step struct {
// contains filtered or unexported fields
}
func NewStep ¶
func (*Step) After ¶
func (*Step) Before ¶
func (*Step) Run ¶
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
func (Transformer) Transform ¶
func (t Transformer) Transform(f File) (File, error)
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 ¶
confirm.go dir.go disk.go dry_runner.go events.go file.go force.go generator.go genny.go group.go helpers.go logger.go replacer.go results.go runner.go step.go transformer.go version.go wet_runner.go
Directories ¶
Path | Synopsis |
---|---|
depgen | |
genny | |
genny/cmd | |
genny/new | You can use the "packr clean" command to clean up this, and any other packr generated files. |
gentest | |
gitgen | |
gogen | |
gogen/goimports | |
gogen/gomods | |
internal | |
packrd | You can use the "packr2 clean" command to clean up this, and any other packr generated files. |
plushgen |
- Version
- v0.6.0 (latest)
- Published
- Dec 24, 2019
- Platform
- linux/amd64
- Imports
- 25 packages
- Last checked
- 1 week ago –
Tools for package owners.