pipeline

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2021 License: Apache-2.0 Imports: 1 Imported by: 34

README

go-command-pipeline

Go version Version GitHub downloads Codecov

Small Go utility that executes high-level actions in a pipeline fashion

Usage

import pipeline "github.com/ccremer/go-command-pipeline"

func main() {
	p := pipeline.NewPipeline()
	p.WithSteps(
		pipeline.NewStepWithPredicate("clone repository", CloneGitRepository(), pipeline.Not(DirExists("my-repo"))),
		pipeline.NewStep("checkout branch", CheckoutBranch()),
		pipeline.NewStep("pull", Pull()),
	)
	result := p.Run()
	if !result.IsSuccessful() {
		log.Fatal(result.Err)
	}
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ActionFunc

type ActionFunc func() Result

func Abort

func Abort() ActionFunc

type Handler

type Handler func(result Result)

type Logger

type Logger interface {
	Log(message, name string)
}

type Pipeline

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

func NewPipeline

func NewPipeline() *Pipeline

func NewPipelineWithLogger

func NewPipelineWithLogger(logger Logger) *Pipeline

func (*Pipeline) AddStep

func (p *Pipeline) AddStep(step Step) *Pipeline

func (*Pipeline) AsNestedStep

func (p *Pipeline) AsNestedStep(name string, predicate Predicate) Step

func (*Pipeline) Run

func (p *Pipeline) Run() Result

func (*Pipeline) WithAbortHandler

func (p *Pipeline) WithAbortHandler(handler Handler) *Pipeline

func (*Pipeline) WithSteps

func (p *Pipeline) WithSteps(steps ...Step) *Pipeline

type Predicate

type Predicate func(step Step) bool

func And

func And(p1, p2 Predicate) Predicate

func Bool

func Bool(v bool) Predicate

func False

func False() Predicate

func Not

func Not(predicate Predicate) Predicate

func True

func True() Predicate

type Result

type Result struct {
	Abort bool
	Err   error
}

func (Result) IsSuccessful

func (r Result) IsSuccessful() bool

type Step

type Step struct {
	Name string
	F    ActionFunc
	P    Predicate
}

func NewIfElseStep

func NewIfElseStep(name string, predicate Predicate, trueAction, falseAction ActionFunc) Step

func NewStep

func NewStep(name string, action ActionFunc) Step

func NewStepWithPredicate

func NewStepWithPredicate(name string, action ActionFunc, predicate Predicate) Step

Jump to

Keyboard shortcuts

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