genny: Index | Files | Directories

package genny

import ""

Package genny is a _framework_ for writing modular generators, it however, doesn't actually generate anything. It just makes it easier for you to. :)


Package 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 wet_runner.go


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.


var DefaultLogLvl = logger.InfoLevel

func Confirm Uses

func Confirm(msg string) bool

func ForceBox Uses

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

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

func HasExt Uses

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

type DeleteFn Uses

type DeleteFn func()

type Dir Uses

type Dir struct {
    Perm os.FileMode

type Disk Uses

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 Uses

func (d *Disk) Add(f File)

Add file to the virtual disk

func (*Disk) AddBox Uses

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

func (*Disk) Delete Uses

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

Delete calls the Runner#Delete function

func (*Disk) Files Uses

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

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

func (*Disk) Find Uses

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 Uses

func (d *Disk) Remove(name string)

Remove a file(s) from the virtual disk.

type File Uses

type File = packd.SimpleFile

File interface for working with files

func NewDir Uses

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

func NewFile Uses

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 Uses

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

func NewFileS Uses

func NewFileS(name string, s string) File

func StripExt Uses

func StripExt(f File, ext string) File

StripExt from a File and return a new one

type Generator Uses

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 Uses

func New() *Generator

New, well-formed, generator

func (*Generator) Box Uses

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 Uses

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

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

func (*Generator) File Uses

func (g *Generator) File(f File)

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

func (*Generator) Merge Uses

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

func (*Generator) RunFn Uses

func (g *Generator) RunFn(fn RunFn)

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

func (*Generator) Transform Uses

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

func (*Generator) Transformer Uses

func (g *Generator) Transformer(t Transformer)

Transformer adds a file transform to the generator

type Group Uses

type Group struct {
    Generators []*Generator
    // contains filtered or unexported fields

func (*Group) Add Uses

func (gg *Group) Add(g *Generator)

func (*Group) Merge Uses

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

func (*Group) With Uses

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

type Logger Uses

type Logger = logger.Logger

Logger interface for a logger to be used with genny. Logrus is 100% compatible.

type RequestResult Uses

type RequestResult struct {
    Request  *http.Request
    Response *http.Response
    Client   *http.Client
    Error    error

type Results Uses

type Results struct {
    Files    []File
    Commands []*exec.Cmd
    Requests []RequestResult

func (Results) Find Uses

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

type RunFn Uses

type RunFn func(r *Runner) error

func Force Uses

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 Uses

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 Uses

func DryRunner(ctx context.Context) *Runner

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

func NewRunner Uses

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 Uses

func WetRunner(ctx context.Context) *Runner

WetRunner will execute commands and write files it is DESTRUCTIVE

func (*Runner) Chdir Uses

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 Uses

func (r *Runner) Delete(path string) error

func (*Runner) Exec Uses

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

Exec can be used inside of Generators to run commands

func (*Runner) File Uses

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

File can be used inside of Generators to write files

func (*Runner) FindFile Uses

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

func (*Runner) FindStep Uses

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

func (*Runner) LookPath Uses

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

func (*Runner) ReplaceStep Uses

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

func (*Runner) Request Uses

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

func (*Runner) RequestWithClient Uses

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

func (*Runner) Results Uses

func (r *Runner) Results() Results

func (*Runner) Run Uses

func (r *Runner) Run() error

func (*Runner) Steps Uses

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

func (*Runner) With Uses

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

With adds a Generator to the Runner

func (*Runner) WithFn Uses

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 Uses

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

func (*Runner) WithNew Uses

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 Uses

func (r *Runner) WithRun(fn RunFn)

func (*Runner) WithStep Uses

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

type Step Uses

type Step struct {
    // contains filtered or unexported fields

func NewStep Uses

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

func (*Step) After Uses

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

func (*Step) Before Uses

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

func (*Step) Run Uses

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

type Transformer Uses

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

func Dot Uses

func Dot() Transformer

Dot will convert -dot- in a file name to just a . example -dot-travis.yml becomes .travis.yml

func NewTransformer Uses

func NewTransformer(ext string, fn TransformerFn) Transformer

func Replace Uses

func Replace(search string, replace string) Transformer

Replace search/replace in a file name

func (Transformer) Transform Uses

func (t Transformer) Transform(f File) (File, error)

type TransformerFn Uses

type TransformerFn func(File) (File, error)

func ForceFile Uses

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.



Package genny imports 24 packages (graph) and is imported by 103 packages. Updated 2020-03-24. Refresh now. Tools for package owners.