Documentation ¶
Overview ¶
Package cmdr Provide for quick build and run a cmd, batch run multi cmd tasks
Index ¶
- func FirstLine(output string) string
- func OutputLines(output string) []string
- func PrintCmdline(c *Cmd)
- type Cmd
- func (c *Cmd) AddArg(args ...string) *Cmd
- func (c *Cmd) AddArgf(format string, args ...any) *Cmd
- func (c *Cmd) AddArgs(args []string) *Cmd
- func (c *Cmd) AppendEnv(mp map[string]string) *Cmd
- func (c *Cmd) ArgIf(arg string, exprOk bool) *Cmd
- func (c *Cmd) BinName() string
- func (c *Cmd) BinOrPath() string
- func (c *Cmd) Cmdline() string
- func (c *Cmd) CombinedOutput() (string, error)
- func (c *Cmd) Config(fn func(c *Cmd)) *Cmd
- func (c *Cmd) Copy(args ...string) *Cmd
- func (c *Cmd) FlushRun() error
- func (c *Cmd) GoCmd() *exec.Cmd
- func (c *Cmd) HasStdout() bool
- func (c *Cmd) IDString() string
- func (c *Cmd) MustRun()
- func (c *Cmd) OnAfter(fn func(c *Cmd, err error)) *Cmd
- func (c *Cmd) OnBefore(fn func(c *Cmd)) *Cmd
- func (c *Cmd) OnlyArgs() (ss []string)
- func (c *Cmd) Output() (string, error)
- func (c *Cmd) OutputLines() ([]string, error)
- func (c *Cmd) OutputToOS() *Cmd
- func (c *Cmd) PrintCmdline() *Cmd
- func (c *Cmd) ResetArgs()
- func (c *Cmd) Run() error
- func (c *Cmd) SafeLines() []string
- func (c *Cmd) SafeOutput() string
- func (c *Cmd) SetVar(name, val string) *Cmd
- func (c *Cmd) Success() bool
- func (c *Cmd) ToOSStdout() *Cmd
- func (c *Cmd) ToOSStdoutStderr() *Cmd
- func (c *Cmd) WithAnyArgs(args ...any) *Cmd
- func (c *Cmd) WithArg(args ...string) *Cmd
- func (c *Cmd) WithArgIf(arg string, exprOk bool) *Cmd
- func (c *Cmd) WithArgf(format string, args ...any) *Cmd
- func (c *Cmd) WithArgs(args []string) *Cmd
- func (c *Cmd) WithArgsIf(args []string, exprOk bool) *Cmd
- func (c *Cmd) WithBin(name string) *Cmd
- func (c *Cmd) WithDryRun(dryRun bool) *Cmd
- func (c *Cmd) WithEnvMap(mp map[string]string) *Cmd
- func (c *Cmd) WithGoCmd(ec *exec.Cmd) *Cmd
- func (c *Cmd) WithOutput(out, errOut io.Writer) *Cmd
- func (c *Cmd) WithStdin(in io.Reader) *Cmd
- func (c *Cmd) WithVars(vs map[string]string) *Cmd
- func (c *Cmd) WithWorkDir(dir string) *Cmd
- func (c *Cmd) WorkDirOnNE(dir string) *Cmd
- func (c *Cmd) Workdir() string
- type Runner
- func (r *Runner) Add(tasks ...*Task) *Runner
- func (r *Runner) AddCmd(cmds ...*Cmd) *Runner
- func (r *Runner) AddCmdline(line string) *Runner
- func (r *Runner) AddTask(task *Task) *Runner
- func (r *Runner) CmdWithAnys(cmdName string, args ...any) *Runner
- func (r *Runner) CmdWithArgs(cmdName string, args ...string) *Runner
- func (r *Runner) GitCmd(subCmd string, args ...string) *Runner
- func (r *Runner) Len() int
- func (r *Runner) Prev() *Task
- func (r *Runner) Reset() *Runner
- func (r *Runner) Run() error
- func (r *Runner) RunTask(task *Task) (goon bool)
- func (r *Runner) StepRun() error
- func (r *Runner) Task(id string) (*Task, error)
- func (r *Runner) TaskIDs() []string
- func (r *Runner) WithOutToStd() *Runner
- type RunnerHookFn
- type Task
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Cmd ¶
type Cmd struct { *exec.Cmd // Name of the command Name string // DryRun if True, not real execute command DryRun bool // Vars mapping Vars map[string]string // BeforeRun hook BeforeRun func(c *Cmd) // AfterRun hook AfterRun func(c *Cmd, err error) }
Cmd struct
func CmdWithCtx ¶ added in v0.6.0
CmdWithCtx create new instance with context.
see exec.CommandContext
func (*Cmd) CombinedOutput ¶
CombinedOutput run and return output, will combine stderr and stdout output
func (*Cmd) OutputLines ¶
OutputLines run and return output as lines
func (*Cmd) OutputToOS ¶ added in v0.6.2
OutputToOS output to OS stdout and error
func (*Cmd) PrintCmdline ¶ added in v0.6.6
PrintCmdline on exec command
func (*Cmd) ToOSStdout ¶ added in v0.6.2
ToOSStdout output to OS stdout
func (*Cmd) ToOSStdoutStderr ¶ added in v0.6.2
ToOSStdoutStderr output to OS stdout and error
func (*Cmd) WithAnyArgs ¶ added in v0.6.0
WithAnyArgs add args and returns the current object.
func (*Cmd) WithArgsIf ¶
WithArgsIf add arg and returns the current object
func (*Cmd) WithDryRun ¶ added in v0.6.6
WithDryRun on exec command
func (*Cmd) WithEnvMap ¶ added in v0.6.7
WithEnvMap override set new ENV for run
func (*Cmd) WithOutput ¶
WithOutput returns the current instance
func (*Cmd) WithWorkDir ¶
WithWorkDir returns the current object
func (*Cmd) WorkDirOnNE ¶ added in v0.6.6
WorkDirOnNE set workdir on input is not empty
type Runner ¶
type Runner struct { // Errs on run tasks, key is Task.ID Errs errorx.ErrMap // Workdir common workdir Workdir string // EnvMap will append to task.Cmd on run EnvMap map[string]string // Params for add custom params Params maputil.Map // DryRun dry run all commands DryRun bool // OutToStd stdout and stderr OutToStd bool // IgnoreErr continue on error IgnoreErr bool // BeforeRun hooks on each task. return false to skip current task. BeforeRun func(r *Runner, t *Task) bool // AfterRun hook on each task. return false to stop running. AfterRun func(r *Runner, t *Task) bool // contains filtered or unexported fields }
Runner use for batch run multi task commands
func (*Runner) AddCmdline ¶ added in v0.6.6
AddCmdline as a command task
func (*Runner) CmdWithAnys ¶ added in v0.6.0
CmdWithAnys a command task
func (*Runner) CmdWithArgs ¶ added in v0.6.0
CmdWithArgs a command task
func (*Runner) WithOutToStd ¶ added in v0.6.8
WithOutToStd set
type RunnerHookFn ¶ added in v0.6.8
RunnerHookFn func