generator

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2020 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SkipErrors added in v0.2.0

func SkipErrors(r *Runner)

Types

type BlueprintParser

type BlueprintParser interface {
	Parse(b []byte) (*blueprint, error)
}

type FileTreeReader added in v0.2.0

type FileTreeReader interface {
	// ReadFile reads the file from file tree named by filename and returns
	// the contents.
	ReadFile(filename string) ([]byte, error)

	// Walk walks the file tree, calling walkFn for each file or directory
	// in the tree, including root. All errors that arise visiting files
	// and directories are filtered by walkFn.
	Walk(walkFn func(filepath string, isDir bool, err error) error) error
}

FileTreeReader is an abstraction over any system-agnostic file tree. In the case of generator, it provides full structure, that should be scanned, read and generated at the filepath relative to the working directory.

type Filesystem

type Filesystem interface {
	WriteFile(name string, data []byte, perm os.FileMode) error
	MkdirAll(path string, perm os.FileMode) error
	Stat(name string) (os.FileInfo, error)
}

type Logger added in v0.2.0

type Logger interface {
	Debug(v ...interface{})
	Info(v ...interface{})
}

type NopLogger added in v0.2.0

type NopLogger struct{}

func (NopLogger) Debug added in v0.2.0

func (l NopLogger) Debug(_ ...interface{})

func (NopLogger) Info added in v0.2.0

func (l NopLogger) Info(_ ...interface{})

type OnErrorFn

type OnErrorFn func(err error) bool

OnErrorFn is called if error occurred when processing file. Return true to skip the file and continue process, or false to terminate Runner and return the error.

type OnExistsFn

type OnExistsFn func(path string) bool

OnExistsFn handles files that already exist at target path. Return true to overwrite file or false to skip it.

type OnSuccessFn

type OnSuccessFn func(src, dst string)

OnSuccessFn is called on each successfully generated file. First argument holds path of the source file, and second argument - path of the generated file.

type OptionFn added in v0.2.0

type OptionFn func(*Runner)

func IgnorePath added in v0.2.0

func IgnorePath(p string) OptionFn

func OnFileExists

func OnFileExists(fn OnExistsFn) OptionFn

func WithLogger added in v0.2.0

func WithLogger(l Logger) OptionFn

type RunError

type RunError struct {
	Err  error
	Path string
}

func (*RunError) Error

func (e *RunError) Error() string

func (*RunError) Unwrap

func (e *RunError) Unwrap() error

type Runner

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

func NewRunner

func NewRunner(fs Filesystem, bp BlueprintParser, dir string, options ...OptionFn) *Runner

func (*Runner) Run

func (r *Runner) Run(ftr FileTreeReader) error

Run generates all the files from FileTreeReader by walking over each file, reading it and writing it at relative path in working directory. If file ends with extension `.accio`, then it's parsed with BlueprintParser, which returns file's content and additional metadata, like custom filepath, and whether file should be skipped.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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