manager

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2018 License: MPL-2.0 Imports: 13 Imported by: 1

Documentation

Index

Constants

View Source
const (
	// DefaultFilePerms are the default file permissions for files rendered onto
	// disk when a specific file permission has not already been specified.
	DefaultFilePerms = 0644
)

Variables

View Source
var (
	// ErrNoParentDir is the error returned with the parent directory is missing
	// and the user disabled it.
	ErrNoParentDir = errors.New("parent directory is missing")

	// ErrMissingDest is the error returned with the destination is empty.
	ErrMissingDest = errors.New("missing destination")
)

Functions

func AtomicWrite

func AtomicWrite(path string, createDestDirs bool, contents []byte, perms os.FileMode, backup bool) error

AtomicWrite accepts a destination path and the template contents. It writes the template contents to a TempFile on disk, returning if any errors occur.

If the parent destination directory does not exist, it will be created automatically with permissions 0755. To use a different permission, create the directory first or use `chmod` in a Command.

If the destination path exists, all attempts will be made to preserve the existing file permissions. If those permissions cannot be read, an error is returned. If the file does not exist, it will be created automatically with permissions 0644. To use a different permission, create the destination file first or use `chmod` in a Command.

If no errors occur, the Tempfile is "renamed" (moved) to the destination path.

Types

type ErrChildDied

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

ErrChildDied is the error returned when the child process prematurely dies.

func NewErrChildDied

func NewErrChildDied(c int) *ErrChildDied

NewErrChildDied creates a new error with the given exit code.

func (*ErrChildDied) Error

func (e *ErrChildDied) Error() string

Error implements the error interface.

func (*ErrChildDied) ExitStatus

func (e *ErrChildDied) ExitStatus() int

ExitStatus implements the ErrExitable interface.

type ErrExitable

type ErrExitable interface {
	ExitStatus() int
}

ErrExitable is an interface that defines an integer ExitStatus() function.

type RenderInput

type RenderInput struct {
	Backup         bool
	Contents       []byte
	CreateDestDirs bool
	Dry            bool
	DryStream      io.Writer
	Path           string
	Perms          os.FileMode
}

RenderInput is used as input to the render function.

type RenderResult

type RenderResult struct {
	// DidRender indicates if the template rendered to disk. This will be false in
	// the event of an error, but it will also be false in dry mode or when the
	// template on disk matches the new result.
	DidRender bool

	// WouldRender indicates if the template would have rendered to disk. This
	// will return false in the event of an error, but will return true in dry
	// mode or when the template on disk matches the new result.
	WouldRender bool

	// Contents are the actual contents of the resulting template from the render
	// operation.
	Contents []byte
}

RenderResult is returned and stored. It contains the status of the render operation.

func Render

func Render(i *RenderInput) (*RenderResult, error)

Render atomically renders a file contents to disk, returning a result of whether it would have rendered and actually did render.

type Runner

type Runner struct {
	ErrCh  chan error
	DoneCh chan bool
	// contains filtered or unexported fields
}

Runner responsible rendering Templates and invoking Commands.

func NewRunner

func NewRunner(config *config.Config, dry, once bool) (*Runner, error)

NewRunner accepts a slice of TemplateConfigs and returns a pointer to the new Runner and any error that occurred during creation.

func (*Runner) Run

func (r *Runner) Run() error

Run iterates over each template in this Runner and conditionally executes the template rendering and command execution.

The template is rendered atomically. If and only if the template render completes successfully, the optional commands will be executed, if given. Please note that all templates are rendered **and then** any commands are executed.

func (*Runner) SetErrStream

func (r *Runner) SetErrStream(err io.Writer)

SetErrStream modifies runner error stream. Defaults to stderr.

func (*Runner) SetOutStream

func (r *Runner) SetOutStream(out io.Writer)

SetOutStream modifies runner output stream. Defaults to stdout.

func (*Runner) Start

func (r *Runner) Start()

Start begins the polling for this runner. Any errors that occur will cause this function to push an item onto the runner's error channel and the halt execution. This function is blocking and should be called as a goroutine.

func (*Runner) Stop

func (r *Runner) Stop()

Stop halts the execution of this runner and its subprocesses.

Jump to

Keyboard shortcuts

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