processors

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 29, 2021 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package processors implements a file processing framework.

Index

Constants

This section is empty.

Variables

View Source
var ErrNotProcessable = errors.New("not a processable file")

ErrNotProcessable means that a file didn't match a registered file name or extension by a processor to run. This really just means no-op occurred on the file in regards to it being processed.

Functions

This section is empty.

Types

type Config

type Config struct {
	// The name of the processor.
	Name string

	// FileExtensions are the file extensions this processor should handle
	FileExtensions []string

	// FileNames are specific files this processor should handle
	FileNames []string

	// IsPreCodegenProcessor denotes whether or not the given processor should
	// be ran before codegen starts.
	IsPreCodegenProcessor bool

	// IsPostCodegenProcessor denotes whether or not the given processor
	// should be ran after the codegen stage of bootstrap. The main difference
	// between running a processor during the codegen stage and after the
	// codegen stage are the files each touches, respectively. The codegen
	// processors will only touch non-static files generated by bootstrap,
	// whereas post-codegen processors will touch every file of the repository,
	// regardless of whether or not it was generated by bootstrap or not.
	// Template does not get passed to Process function (see Processor
	// interface) when this bool is set to true.
	IsPostCodegenProcessor bool

	// RerunCodegen denotes that after all of the processors have ran post-codegen,
	// rerun codegen. This will only fire if IsPostCodegenProcessor is also true.
	RerunCodegen bool

	// VersionGate denotes the version at which the processor should be ran and
	// implies that any versions before this version should also be ran on. For
	// example, if VersionGate was 8.1.4, the processor would be ran on all
	// previous versions of bootstrap (what is found in bootstrap.lock before
	// codegen begins) <= 8.1.4. It would not be ran on versions > 8.1.4.
	//
	// This also implies that if the previous version (what is found in bootstrap.lock
	// before codegen begins) is nil (which is the case when a repository is freshly
	// bootstrapped), the processor will not run as it shouldn't have any anything to
	// migrate on a fresh repository.
	VersionGate *semver.Version
}

Config is the configuration metadata for a Processor.

type File

type File struct {
	io.Reader

	Name string
}

File is a small wrapper around an io.Reader, used for processing files in individual types that implement the Processor interface.

func NewFile

func NewFile(r io.Reader, path string) *File

NewFile create a new file. If r is nil, a nil file is returned.

type Processor

type Processor interface {
	// Register configures this processor.
	Register() *Config

	// Config returns the config set on the processor, usually set by Register.
	Config() *Config

	// Process process a file and returns it
	Process(*File, *File) (*File, error)
}

Processor defines the interface that a processor must implement to run.

type Runner added in v1.1.0

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

Runner is used to execute several processors on individual files.

func New

func New(log logrus.FieldLogger, previousVersion *semver.Version) *Runner

New creates a new runner using all of the registered processors in registeredProcecssors.

func (*Runner) RunDuringCodegen added in v1.1.0

func (r *Runner) RunDuringCodegen(existing, template *File) (*File, error)

RunDuringCodegen runs all of the processors that are neither pre-codegen or post-codegen specific processors.

func (*Runner) RunPostCodegen added in v1.1.0

func (r *Runner) RunPostCodegen(existing, template *File) (*File, error)

RunPostCodegen runs all of the post-codegen processors.

func (*Runner) RunPreCodegen added in v1.1.0

func (r *Runner) RunPreCodegen(existing, template *File) (*File, error)

RunPreCodegen runs all of the pre-codegen processors.

func (*Runner) ShouldRerunPostCodegen added in v1.1.0

func (r *Runner) ShouldRerunPostCodegen() bool

ShouldRerunPostCodegen checks to see if there are any post-codegen processors that require codegen to be reran after they run.

Jump to

Keyboard shortcuts

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