ptasks

package module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: May 27, 2020 License: MIT Imports: 13 Imported by: 0

README

Ptasks

Lib for running tasks in parallel with nice output.

You can also use as a command line by doing:

go get github.com/ArthurHlt/ptasks/cmd/ptasks

You could now perform:

$ cat myfilecontainingcmd.txt | ptasks -v

Example of usage:

see /cmd/ptasks/main.go

subset:

func main(){
    t := ptasks.NewPtask(os.Stdout, func(job *ptasks.Job) {
        task := job.Data.(CmdTask)
        err := RunProcess(ProcessOpts{
            Cmd:     task.cmd,
            EnvVars: os.Environ(),
            Stdout:  job.Buffer(),
            Stderr:  job.Buffer(),
            WithPty: opts.ForceTty || isTTY,
            Stdin:   task.r,
            WorkDir: wd,
        })
        if err != nil {
            job.SetError(err)
        }
    },
        ptasks.AllInOneOpt(opts.OnlyErrors, !opts.Verbose && !opts.OnlyErrors, opts.Compact, opts.ForceTty, opts.NotDrawable, false),
    )
    err = t.Run(jobs, opts.NbWorker)
}

Command line ptasks

Usage:
  ptasks [OPTIONS]

Application Options:
  -v, --verbose        Set to pass in verbose mode.
  -e, --only-errors    See only error on verbose output.
  -t, --tty            Force use of tty for color output
  -d, --not-drawable   Do not perform terminal draw
  -n, --number-worker= number of worker to use (default: 4)
  -i, --file-input=    input to give to stdin in task, this must be a file path
  -c, --compact        Set it to use compact form, this will not describe each script.

Help Options:
  -h, --help           Show this help message

Usage:
  ptasks [OPTIONS]

Application Options:
  -v, --verbose        Set to pass in verbose mode.
  -e, --only-errors    See only error on verbose output.
  -t, --tty            Force use of tty for color output
  -d, --not-drawable   Do not perform terminal draw
  -n, --number-worker= number of worker to use (default: 4)
  -i, --file-input=    input to give to stdin in task, this must be a file path
  -c, --compact        Set it to use compact form, this will not describe each script.

Help Options:
  -h, --help           Show this help message

Documentation

Index

Constants

View Source
const (
	JobStateWait jobState = 1 << iota
	JobStateRun
	JobStateFinish
)

Variables

This section is empty.

Functions

func AllInOneOpt

func AllInOneOpt(onlyErrors, noVerbose, compact, forceTty, notDrawable, noHeader bool) optFunc

see details on other optFunc

func CompactOpt

func CompactOpt(compact bool) optFunc

Do not see details from each task, only set fail or ok in output

func ForceTtyOpt

func ForceTtyOpt(forceTty bool) optFunc

Force to use a tty for getting color output

func IsErrErrJobs

func IsErrErrJobs(err error) bool

func NoVerboseOpt

func NoVerboseOpt(noVerbose bool) optFunc

do not show output from task

func NotDrawableOpt

func NotDrawableOpt(notDrawable bool) optFunc

Do not draw tasks for refreshing their state in output This will only output details when all tasks complete

func NotHeaderOpt

func NotHeaderOpt(noHeader bool) optFunc

Do not write `Running all tasks in parallel with...` in output

func OnlyErrorsOpt

func OnlyErrorsOpt(onlyErrors bool) optFunc

only show output from errored task

func ParseCommands

func ParseCommands(cmdRaw string) ([][]string, error)

Types

type ErrJobs

type ErrJobs struct {
	Jobs []*Job
}

func NewErrJobs

func NewErrJobs(jobs []*Job) *ErrJobs

func (ErrJobs) Error

func (e ErrJobs) Error() string

type FanoutReader

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

func NewFanoutReader

func NewFanoutReader(source io.Reader) *FanoutReader

func (*FanoutReader) AddWriter

func (f *FanoutReader) AddWriter(writer io.Writer)

func (*FanoutReader) Fanout

func (f *FanoutReader) Fanout() error

type Job

type Job struct {
	Name string
	Data interface{}
	// contains filtered or unexported fields
}

func NewJob

func NewJob(name string, data interface{}) *Job

func (*Job) Buffer

func (j *Job) Buffer() *bytes.Buffer

func (*Job) DrawOutput

func (j *Job) DrawOutput() string

func (*Job) Header

func (j *Job) Header() string

func (*Job) SetError

func (j *Job) SetError(e error)

type MultiWriters

type MultiWriters []io.Writer

func (MultiWriters) Write

func (m MultiWriters) Write(p []byte) (n int, err error)

type Ptask

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

func NewPtask

func NewPtask(output io.Writer, workerFunc func(*Job), opts ...optFunc) *Ptask

func (*Ptask) CompactPrint

func (c *Ptask) CompactPrint(f string, a ...interface{})

func (*Ptask) CompactPrintln

func (c *Ptask) CompactPrintln(f string, a ...interface{})

func (*Ptask) Run

func (c *Ptask) Run(jobs []*Job, parallel int) error

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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