cmdr

package
v0.5.14 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2022 License: MIT Imports: 7 Imported by: 6

Documentation

Overview

Package cmdr Provide for quick build and run a cmd, batch run multi cmd tasks

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FirstLine

func FirstLine(output string) string

FirstLine from command output

func OutputLines

func OutputLines(output string) []string

OutputLines split output to lines

Types

type Cmd

type Cmd struct {
	*exec.Cmd
	// Name of the command
	Name string
	// RunBefore hook
	RunBefore func(c *Cmd)
	// RunAfter hook
	RunAfter func(c *Cmd, err error)
}

Cmd struct

func NewCmd

func NewCmd(bin string, args ...string) *Cmd

NewCmd instance

func WrapGoCmd

func WrapGoCmd(cmd *exec.Cmd) *Cmd

WrapGoCmd instance

func (*Cmd) AddArg

func (c *Cmd) AddArg(args ...string) *Cmd

AddArg add args and returns the current object

func (*Cmd) AddArgf

func (c *Cmd) AddArgf(format string, args ...interface{}) *Cmd

AddArgf add args and returns the current object. alias of the WithArgf()

func (*Cmd) AddArgs

func (c *Cmd) AddArgs(args []string) *Cmd

AddArgs for the git. alias of WithArgs()

func (*Cmd) ArgIf

func (c *Cmd) ArgIf(arg string, exprOk bool) *Cmd

ArgIf add arg and returns the current object

func (*Cmd) Cmdline

func (c *Cmd) Cmdline() string

Cmdline to command line

func (*Cmd) CombinedOutput

func (c *Cmd) CombinedOutput() (string, error)

CombinedOutput run and return output, will combine stderr and stdout output

func (*Cmd) FlushRun

func (c *Cmd) FlushRun() error

FlushRun runs command and flush output to stdout

func (*Cmd) GoCmd

func (c *Cmd) GoCmd() *exec.Cmd

GoCmd get exec.Cmd

func (*Cmd) IDString

func (c *Cmd) IDString() string

IDString of the command

func (*Cmd) MustRun

func (c *Cmd) MustRun()

MustRun a command. will panic on error

func (*Cmd) OnAfter

func (c *Cmd) OnAfter(fn func(c *Cmd, err error)) *Cmd

OnAfter exec add hook

func (*Cmd) OnBefore

func (c *Cmd) OnBefore(fn func(c *Cmd)) *Cmd

OnBefore exec add hook

func (*Cmd) Output

func (c *Cmd) Output() (string, error)

Output run and return output

func (*Cmd) OutputLines

func (c *Cmd) OutputLines() ([]string, error)

OutputLines run and return output as lines

func (*Cmd) OutputToStd

func (c *Cmd) OutputToStd() *Cmd

OutputToStd output to OS stdout and error

func (*Cmd) ResetArgs

func (c *Cmd) ResetArgs()

ResetArgs for git

func (*Cmd) Run

func (c *Cmd) Run() error

Run runs command

func (*Cmd) SafeLines

func (c *Cmd) SafeLines() []string

SafeLines run and return output as lines

func (*Cmd) SafeOutput

func (c *Cmd) SafeOutput() string

SafeOutput run and return output

func (*Cmd) Success

func (c *Cmd) Success() bool

Success run and return whether success

func (*Cmd) WithArg

func (c *Cmd) WithArg(args ...string) *Cmd

WithArg add args and returns the current object. alias of the WithArg()

func (*Cmd) WithArgIf

func (c *Cmd) WithArgIf(arg string, exprOk bool) *Cmd

WithArgIf add arg and returns the current object

func (*Cmd) WithArgf

func (c *Cmd) WithArgf(format string, args ...interface{}) *Cmd

WithArgf add arg and returns the current object

func (*Cmd) WithArgs

func (c *Cmd) WithArgs(args []string) *Cmd

WithArgs for the git

func (*Cmd) WithArgsIf

func (c *Cmd) WithArgsIf(args []string, exprOk bool) *Cmd

WithArgsIf add arg and returns the current object

func (*Cmd) WithOutput

func (c *Cmd) WithOutput(out, errOut io.Writer) *Cmd

WithOutput returns the current argument

func (*Cmd) WithStdin

func (c *Cmd) WithStdin(in io.Reader) *Cmd

WithStdin returns the current argument

func (*Cmd) WithWorkDir

func (c *Cmd) WithWorkDir(dir string) *Cmd

WithWorkDir returns the current object

type Errs

type Errs map[string]error

Errs on run tasks. key is Task.ID

func (Errs) Error

func (e Errs) Error() string

Error string

func (Errs) IsEmpty

func (e Errs) IsEmpty() bool

IsEmpty error

func (Errs) One

func (e Errs) One() error

One error

type Runner

type Runner struct {

	// Errs on run tasks
	Errs Errs

	// IgnoreErr continue on error
	IgnoreErr  bool
	RunBefore  func(r *Runner) bool
	RunAfter   func(r *Runner)
	ListenPrev func(t *Task) bool
	EachBefore func(c *Cmd) bool
	// contains filtered or unexported fields
}

Runner use for batch run multi task commands

func NewRunner

func NewRunner() *Runner

NewRunner instance

func (*Runner) Add

func (r *Runner) Add(tasks ...*Task) *Runner

Add multitask at once

func (*Runner) AddCmd

func (r *Runner) AddCmd(cmds ...*Cmd) *Runner

AddCmd commands

func (*Runner) AddTask

func (r *Runner) AddTask(task *Task) *Runner

AddTask add one task

func (*Runner) Prev

func (r *Runner) Prev() *Task

Prev task instance after running

func (*Runner) Run

func (r *Runner) Run() error

Run all tasks

func (*Runner) Task

func (r *Runner) Task(id string) (*Task, error)

Task get by id name

func (*Runner) TaskIDs

func (r *Runner) TaskIDs() []string

TaskIDs get

type Task

type Task struct {

	// ID for task
	ID  string
	Cmd *Cmd

	// RunBefore hook
	RunBefore func() bool
	PrevCond  func(prev *Task) bool
	// contains filtered or unexported fields
}

Task struct

func (*Task) Err

func (t *Task) Err() error

Err get

Jump to

Keyboard shortcuts

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