exec

package
v0.59.0 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2024 License: BSD-3-Clause Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ExecFormatJSON  string = "json"
	ExecFormatPlain string = "plain"
)

Variables

View Source
var ErrRunExecNotSupported = errors.New("exec not supported for this kind")

Functions

func ParseExecOutputFormat

func ParseExecOutputFormat(s string) (string, error)

ParseExecOutputFormat parses the exec output format user input.

Types

type ExecCmd

type ExecCmd struct {
	Cmd []string `json:"cmd"` // Cmd is a slice-based representation of a string command.
}

ExecCmd represents an exec command.

func NewExecCmdFromSlice

func NewExecCmdFromSlice(cmd []string) *ExecCmd

NewExecCmdFromSlice creates ExecCmd for a command represented as a slice of strings.

func NewExecCmdFromString

func NewExecCmdFromString(cmd string) (*ExecCmd, error)

NewExecCmdFromString creates ExecCmd for a string-based command.

func (*ExecCmd) GetCmd

func (e *ExecCmd) GetCmd() []string

GetCmd sets the command that is to be executed.

func (*ExecCmd) GetCmdString

func (e *ExecCmd) GetCmdString() string

GetCmdString sets the command that is to be executed.

func (*ExecCmd) SetCmd

func (e *ExecCmd) SetCmd(cmd string) error

SetCmd sets the command that is to be executed.

type ExecCollection

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

ExecCollection represents a datastore for exec commands execution results.

func NewExecCollection

func NewExecCollection() *ExecCollection

NewExecCollection initializes the collection of exec command results.

func (*ExecCollection) Add

func (ec *ExecCollection) Add(cId string, e *ExecResult)

func (*ExecCollection) AddAll

func (ec *ExecCollection) AddAll(cId string, e []*ExecResult)

func (*ExecCollection) Dump

func (ec *ExecCollection) Dump(format string) (string, error)

Dump dumps the contents of ExecCollection as a string in one of the provided formats.

func (*ExecCollection) Log

func (ec *ExecCollection) Log()

Log writes to the log execution results stored in ExecCollection. If execution result contains error, the error log facility is used, otherwise it is logged as INFO.

type ExecResult

type ExecResult struct {
	Cmd        []string `json:"cmd"`
	ReturnCode int      `json:"return-code"`
	Stdout     Stdout   `json:"stdout"`
	Stderr     string   `json:"stderr"`
}

ExecResult represents a result of a command execution.

func NewExecResult

func NewExecResult(op *ExecCmd) *ExecResult

func (*ExecResult) Dump

func (e *ExecResult) Dump(format string) (string, error)

Dump dumps execution result as a string in one of the provided formats.

func (*ExecResult) GetCmd

func (e *ExecResult) GetCmd() []string

func (*ExecResult) GetCmdString

func (e *ExecResult) GetCmdString() string

GetCmdString returns the initially parsed cmd as a string for e.g. log output purpose.

func (*ExecResult) GetReturnCode

func (e *ExecResult) GetReturnCode() int

func (*ExecResult) GetStdErrByteSlice

func (e *ExecResult) GetStdErrByteSlice() []byte

func (*ExecResult) GetStdErrString

func (e *ExecResult) GetStdErrString() string

func (*ExecResult) GetStdOutByteSlice

func (e *ExecResult) GetStdOutByteSlice() []byte

func (*ExecResult) GetStdOutString

func (e *ExecResult) GetStdOutString() string

func (*ExecResult) SetReturnCode

func (e *ExecResult) SetReturnCode(rc int)

func (*ExecResult) SetStdErr

func (e *ExecResult) SetStdErr(data []byte)

func (*ExecResult) SetStdOut

func (e *ExecResult) SetStdOut(data []byte)

func (*ExecResult) String

func (e *ExecResult) String() string

type Stdout added in v0.35.0

type Stdout string

Stdout type alias for a string is an artificial type to allow for custom marshalling of stdout output which can be either a valid or non valid JSON. For that reason a custom MarshalJSON method is implemented to take care of both.

func (Stdout) MarshalJSON added in v0.35.0

func (s Stdout) MarshalJSON() ([]byte, error)

MarshalJSON implements a custom marshaller for a custom Stdout type.

Jump to

Keyboard shortcuts

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