async_script

package module
v0.0.10 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2022 License: MIT Imports: 14 Imported by: 1

README

async-script

Test idea for implementing https://github.com/bitfield/script asynchronously demo gif

Documentation

Overview

Package implements shell like DSL for executing commands and making transformations. Main motivation was to write CI/CD scripts in Go instead of Makefile/bash etc.

Example
packagesForTest := ""
MustRun(
	Exec("go list ./..."),
	ToString(&packagesForTest),
)

packagesForCover := strings.ReplaceAll(packagesForTest, "\n", ",")

MustRun(
	Execf("go test %v -coverpkg=%v -coverprofile=./coverage.out", packagesForTest, packagesForCover),
	Tee("go-test.log"),
)
Output:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func MustRun

func MustRun(pipes ...Op)

The same as Run, but if one of operations fails will call log.Fatal(err) and stops execution

func Run

func Run(pipes ...Op) error

Run a chain of operations similar to shell: $> op1 | op2 | op3 Returns errors if one of the operation fails

func ScanLinesWithoutDrop

func ScanLinesWithoutDrop(data []byte, atEOF bool) (advance int, token []byte, err error)

func ScanWordsWithoutDrop

func ScanWordsWithoutDrop(data []byte, atEOF bool) (advance int, token []byte, err error)

Types

type Op

type Op interface {
	Run() error
	SetInput(io.ReadCloser)
	GetReader() io.ReadCloser
}

func Exec

func Exec(cmd string) Op

Runs shell command

func ExecWithCmd

func ExecWithCmd(cmdString string, cmd exec.Cmd, stderrToStdin bool) Op

func Execf

func Execf(cmd string, a ...interface{}) Op

func Filter

func Filter(match string) Op

func FromFile

func FromFile(path string) Op

Get content of the file and pass it as STDIN to next Op

func Glob

func Glob(path string) Op

func Map

func Map(f func(string) []string) Op

func Replace

func Replace(what, to string) Op

func String

func String() Op

TODO

func Tee

func Tee(path string) Op

func ToFile

func ToFile(path string) Op

func ToString

func ToString(dst *string) Op

func Transformer

func Transformer(splitFunc bufio.SplitFunc, transformFunc func([]byte) []byte) Op
Example
var res string
MustRun(
	Exec("echo one two three"),
	Replace("three", "one"),
	Filter("two"),
	ToString(&res),
)

fmt.Print(res)
Output:

one one

func Watch

func Watch(lines int) Op

type Ops

type Ops []Op

func (*Ops) Add

func (r *Ops) Add(ops ...Op) Ops

type TransformerAsyncPipe

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

func (*TransformerAsyncPipe) GetReader

func (p *TransformerAsyncPipe) GetReader() io.ReadCloser

func (*TransformerAsyncPipe) Run

func (p *TransformerAsyncPipe) Run() error

func (*TransformerAsyncPipe) SetInput

func (p *TransformerAsyncPipe) SetInput(in io.ReadCloser)

type WatchAsyncPipe

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

func (*WatchAsyncPipe) GetReader

func (p *WatchAsyncPipe) GetReader() io.ReadCloser

func (*WatchAsyncPipe) Run

func (p *WatchAsyncPipe) Run() error

func (*WatchAsyncPipe) SetInput

func (p *WatchAsyncPipe) SetInput(in io.ReadCloser)

Directories

Path Synopsis
example

Jump to

Keyboard shortcuts

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