genny – github.com/gobuffalo/genny Index | Files | Directories

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

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 DefaultLogLvl = logger.InfoLevel
var Version = ""

Functions

func Confirm

func Confirm(msg string) bool

func ForceBox

func ForceBox(g *Generator, box packd.Walker, force bool) error

ForceBox will mount each file in the box and wrap it with ForceFile

func GoBin

func GoBin() string

func HasExt

func HasExt(f File, ext ...string) bool

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 Dir struct {
	File
	Perm os.FileMode
}

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

func (d *Disk) Add(f File)

Add file to the virtual disk

func (*Disk) AddBox

func (d *Disk) AddBox(box packd.Walker) error

func (*Disk) Delete

func (d *Disk) Delete(name string) error

Delete calls the Runner#Delete function

func (*Disk) Files

func (d *Disk) Files() []File

Files returns a sorted list of all the files in the disk

func (*Disk) Find

func (d *Disk) Find(name string) (File, error)

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

func (d *Disk) Remove(name string)

Remove a file(s) from the virtual disk.

type File

type File = packd.SimpleFile

File interface for working with files

func NewDir

func NewDir(path string, perm os.FileMode) File

func NewFile

func NewFile(name string, r io.Reader) File

NewFile takes the name of the file you want to write to and a reader to reader from

func NewFileB

func NewFileB(name string, s []byte) File

func NewFileS

func NewFileS(name string, s string) File

func StripExt

func StripExt(f File, ext string) File

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

func (g *Generator) Box(box packd.Walker) error

Box walks through a packr.Box and adds Files for each entry in the box.

func (*Generator) Command

func (g *Generator) Command(cmd *exec.Cmd)

Command adds a command to be run when the generator is run

func (*Generator) File

func (g *Generator) File(f File)

File adds a file to be run when the generator is run

func (*Generator) Merge

func (g1 *Generator) Merge(g2 *Generator)

func (*Generator) RunFn

func (g *Generator) RunFn(fn RunFn)

RunFn adds a generic "runner" function to the generator.

func (*Generator) Transform

func (g *Generator) Transform(f File) (File, error)

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 (gg *Group) Add(g *Generator)

func (*Group) Merge

func (gg *Group) Merge(g2 *Group)

func (*Group) With

func (gg *Group) With(r *Runner)

type Logger

type Logger = logger.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

func (r Results) Find(s string) (File, error)

type RunFn

type RunFn func(r *Runner) error

func Force

func Force(path string, force bool) RunFn

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

func DryRunner(ctx context.Context) *Runner

DryRunner will NOT execute commands and write files it is NOT destructive

func NewRunner

func NewRunner(ctx context.Context) *Runner

NewRunner will NOT execute commands and write files it is NOT destructive it is just the most basic Runner you can have.

func WetRunner

func WetRunner(ctx context.Context) *Runner

WetRunner will execute commands and write files it is DESTRUCTIVE

func (*Runner) Chdir

func (r *Runner) Chdir(path string, fn func() error) error

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 (r *Runner) Delete(path string) error

func (*Runner) Exec

func (r *Runner) Exec(cmd *exec.Cmd) error

Exec can be used inside of Generators to run commands

func (*Runner) File

func (r *Runner) File(f File) error

File can be used inside of Generators to write files

func (*Runner) FindFile

func (r *Runner) FindFile(name string) (File, error)

func (*Runner) FindStep

func (r *Runner) FindStep(name string) (*Step, error)

func (*Runner) LookPath

func (r *Runner) LookPath(s string) (string, error)

func (*Runner) ReplaceStep

func (r *Runner) ReplaceStep(name string, s *Step) error

func (*Runner) Request

func (r *Runner) Request(req *http.Request) (*http.Response, error)

func (*Runner) RequestWithClient

func (r *Runner) RequestWithClient(req *http.Request, c *http.Client) (*http.Response, error)

func (*Runner) Results

func (r *Runner) Results() Results

func (*Runner) Run

func (r *Runner) Run() error

func (*Runner) Steps

func (r *Runner) Steps() []*Step

func (*Runner) With

func (r *Runner) With(g *Generator) error

With adds a Generator to the Runner

func (*Runner) WithFn

func (r *Runner) WithFn(fn func() (*Generator, error)) error

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 (r *Runner) WithGroup(gg *Group)

func (*Runner) WithNew

func (r *Runner) WithNew(g *Generator, err error) error

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 (r *Runner) WithRun(fn RunFn)

func (*Runner) WithStep

func (r *Runner) WithStep(name string, step *Step) error

type Step

type Step struct {
	// contains filtered or unexported fields
}

func NewStep

func NewStep(g *Generator, index int) (*Step, error)

func (*Step) After

func (s *Step) After(g *Generator) DeleteFn

func (*Step) Before

func (s *Step) Before(g *Generator) DeleteFn

func (*Step) Run

func (s *Step) Run(r *Runner) error

type Transformer

type Transformer struct {
	Ext      string
	StripExt bool
	// contains filtered or unexported fields
}

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

type TransformerFn func(File) (File, error)

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

PathSynopsis
depgen
genny
genny/cmd
genny/newYou can use the "packr clean" command to clean up this, and any other packr generated files.
gentest
gitgen
gogen
gogen/goimports
gogen/gomods
internal
packrdYou 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.