cmdhelper

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2021 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNilCmdHelper        = errors.New("nil cmdHelper")
	ErrCommandNotFound     = errors.New("command not found")
	ErrCommandArgsNotFound = errors.New("command arguments not found")
	ErrCommandsMustBeFed   = errors.New("commands must be provided")
)

Functions

func StrArrReplace

func StrArrReplace(spl string, arr, rarr []string) []string

StrArrReplace is to replace an array with a replace array based on a special char rarr(replace array) contains strings that have to be replaced in an order.

Types

type CmdHelper

type CmdHelper struct {
	CommandArgs map[string][]string
	Writer      io.Writer
}

func New

func New(cmds map[string][]string, writer io.Writer) (c *CmdHelper, err error)

func (*CmdHelper) CliRunner

func (c *CmdHelper) CliRunner(name string, input io.Reader, args ...string) (string, error)

func (*CmdHelper) CliRunnerChan

func (c *CmdHelper) CliRunnerChan(name string, input io.Reader, singnal chan<- *exec.Cmd, args ...string) (string, error)

CliRunnerChan is to kill long running commands upon a signal. it sends the *exec.Cmd. Receiver channel will receive it and Kill the process based on conditions

func (*CmdHelper) Format

func (c *CmdHelper) Format(cmdKey, spl string, rarr []string)

Format formats the command array with a given replace arr. It uses spl (special char) parameter to replace it will update the CommandArgs value with a formatted array

func (*CmdHelper) GetFormatted

func (c *CmdHelper) GetFormatted(cmdKey, spl string, rarr []string) []string

GetFormatted formats the command array with a given replace array it uses spl (special char) parameter to replace and then returns an array with all replaced contents this will not update/replace the original array from CommandArgs key

func (*CmdHelper) Run

func (c *CmdHelper) Run(name string, input io.Reader, cmdKey string) (string, error)

Jump to

Keyboard shortcuts

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