harness

package module
v0.0.0-...-31701ed Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2023 License: MIT Imports: 8 Imported by: 0

README

harness

Package harness provides a set of primitives that can be used to build a magefile without having to set everything from the ground up.

documentation: pkg.go.dev/kiwicom/harness

Documentation

Overview

Package harness provides a set of primitives that can be used to build a magefile without having to set everything from the ground up.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Run

func Run(ctx context.Context, program string, opts ...RunnerOpt) error

Run is a helper function to avoid repetition while gracefully handling errors.

Types

type Harness

type Harness struct {
	PreExecHook  Task
	PostExecHook Task
}

Harness is a support structure that runs tasks, the harness can be customized with pre- and post- execution hook functions, where common functionality to all tasks can be defined.

func New

func New(opts ...Option) *Harness

New constructs a harness.

func (*Harness) Execute

func (h *Harness) Execute(ctx context.Context, tasks ...Task) error

Execute a list of tasks inside the harness. Every task inside the harness is run sequentially, showing a consistent output where the task status and timing info are clearly visible.

type Option

type Option func(h *Harness)

func WithPreExecFunc

func WithPreExecFunc(hook Task) Option

WithPreExecFunc allows specifying a task that will be run every execution, before the specific execution tasks are run.

type RunnerOpt

type RunnerOpt func(r *TaskRunner) error

RunnerOpt allows customizing the behavior of the command runner.

func WithAllowErrors

func WithAllowErrors() RunnerOpt

WithAllowErrors allow errors in the command.

func WithArgs

func WithArgs(args ...string) RunnerOpt

WithArgs command arguments.

func WithDir

func WithDir(dir string) RunnerOpt

WithDir sets the directory where the command should be run inside.

func WithEnv

func WithEnv(vars ...string) RunnerOpt

WithEnv sets up environment variables for the command.

func WithErrMsg

func WithErrMsg(msg string) RunnerOpt

WithErrMsg sets a message to be printed when the command fails.

func WithOKMsg

func WithOKMsg(msg string) RunnerOpt

WithOKMsg sets a message to be printed when the command finishes successfully.

func WithStdIn

func WithStdIn(read io.Reader) RunnerOpt

WithStdIn set up stdin reader.

func WithStdOut

func WithStdOut(w io.Writer) RunnerOpt

WithStdOut set up stdout writer.

func WithoutNoise

func WithoutNoise() RunnerOpt

WithoutNoise silences all output for the command; useful when handling that on the caller side.

type Task

type Task func(ctx context.Context) error

Task defines the basic function that the harness executes. Additional configuration and tweaks can be done by using clojures which return Tasks.

type TaskRunner

type TaskRunner struct {
	Executable string
	Arguments  []string
	// contains filtered or unexported fields
}

TaskRunner holds the metadata for a specific command.

func Cmd

func Cmd(ctx context.Context, executable string, opts ...RunnerOpt) (*TaskRunner, error)

Cmd builds a command runner for a specific Executable.

func (*TaskRunner) Exec

func (r *TaskRunner) Exec() error

Exec a command returning its error and pretty printing the ok and error messages.

Directories

Path Synopsis
Package commons contains common tasks that most go projects need as part of their development/deployment processes.
Package commons contains common tasks that most go projects need as part of their development/deployment processes.

Jump to

Keyboard shortcuts

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