static

package
v0.0.0-...-31e061d Latest Latest
Warning

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

Go to latest
Published: Aug 22, 2019 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Do

func Do(destRoot string, opts *Options, actions ...*Action) error

Do recursively materializes files from the static data at srcRoot to destRoot.

By default, it copies files. If a file already exists at the destination, Do will return an error unless force is true.

Additional behavior can be configured by adding a JSON file to the static data, at srcRoot + ".json". The JSON file should consist of a sequence of JSON objects that will be deserialized into fileOptions structs; see the struct docstring for more info.

func ListFiles

func ListFiles(dir string) ([]string, error)

ListFiles returns a listing of files from the static data under dir, recursively. The relative path to each file from dir is returned.

func ReadLocal

func ReadLocal(biomeDir, key string) (string, error)

ReadLocal reads a local Terraform variable from main.tf. The local variable was likely added using an Action returned from AddLocal. If the variable is not found, it returns the empty string and no error. TODO(rvangent): This function doesn't feel like it belongs in this package; consider moving it or renaming the package.

Types

type Action

type Action struct {
	// SourceContent specifies the source content to be instantiated.
	// Exactly one of SourceContent/SourcePath should be specified.
	SourceContent []byte

	// SourcePath is a full path to a file in the static data to be used as
	// the source content.
	// Exactly one of SourceContent/SourcePath should be specified.
	SourcePath string

	// DestRelPath is the destination path, relative to the destRoot
	// provided to Do.
	DestRelPath string

	// TemplateData set to a non-nil value causes the source content to
	// be parsed and executed as a Go template
	// (see https://golang.org/pkg/text/template/). TemplateData will be
	// passed to Execute. The result of executing the template will then
	// be used as the source content.
	// NOTE: We can't just treat every file as a template; some content
	// files include template directives that should not be interpolated at
	// copy time. For example, the .go files for demos include constants
	// for the HTML they generate which include template directives. We
	// chose to default to treating source files as raw bytes rather than
	// as template because most files are copied as is, and it would be
	// surprising if including a template directive accidentally (e.g.,
	// a stray "{{") caused things to break.
	TemplateData interface{}

	// DestExists must be set to true if the content is being added to an
	// existing file. If the destination file does not exist, Do will return
	// an error.
	// See InsertMarker for where the content will be added, and
	// SkipMarker to identify if the content has already been added.
	DestExists bool

	// SkipMarker is used when DestExists is true, to determine whether
	// the addition has already occurred, and therefore this action should
	// be skipped. It defaults to the source content.
	SkipMarker string

	// InsertMarker is used when DestExists is true, to determine where in
	// the destinatation file the source content is inserted. If empty, the
	// source content is appended to the end of the file. Otherwise, it is
	// inserted into the file at the next line after the marker. If the
	// marker is not found, an error is returned.
	InsertMarker string

	// Description is used when DestExists is true, to describe the content
	// that was added in log messages via Options.Logger.
	// Log messages are of the form "added <Description> to <filename>".
	Description string
}

Action represents an action relative to static content that will be performed in Do. TODO(rvangent): Consider unexporting most of the fields; only TemplateData is currently used externally, and the helpers in this package are used to construct Actions.

func AddLocal

func AddLocal(key, val string) *Action

AddLocal returns an Action that will add a Terraform variable to the "locals" section in main.tf. val is expected to be a constant string and is therefore quoted. The value can later be read using ReadLocal.

func AddOutputVar

func AddOutputVar(key, val string) *Action

AddOutputVar returns an Action that will add a Terraform output variable to outputs.tf. val is expected to be an expression and is therefore not quoted.

func AddProvider

func AddProvider(provider string) *Action

AddProvider returns an Action that will add a Terraform provider to main.tf.

It pulls content from the static data under /providers/<provider>.tf and appends to main.tf.

func CopyDir

func CopyDir(srcRoot string) ([]*Action, error)

CopyDir returns a slice of Action that recursively copy all of the files under srcRoot in the static data to the same paths relative to the destRoot passed to Do.

func CopyFile

func CopyFile(srcPath, destRelPath string) *Action

CopyFile returns an Action that copies a single file from the static data at srcPath to destRelPath. destRelPath is relative to the destRoot passed to Do.

type Options

type Options struct {
	// Force allows Do to clobber existing files when copying.
	Force bool
	// Logger is used to log information about changes.
	Logger Printer
}

Options holds options for Do.

type Printer

type Printer interface {
	Printf(format string, args ...interface{})
}

Printer supports printing messages.

Directories

Path Synopsis
_assets

Jump to

Keyboard shortcuts

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