command

package
v1.6.2 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CmdExecutor

type CmdExecutor interface {
	RunCmd(cmd interface{}, opts ...Options) (string, string, error)
	SetLevel(level logrus.Level)
	RunCmdWithAttempts(cmd interface{}, attempts int, timeout time.Duration, opts ...Options) (string, string, error)
}

CmdExecutor is the interface for executor that runs linux commands with RunCmd

type CmdName

type CmdName string

CmdName represents command name without specified arguments

func (CmdName) Apply

func (c CmdName) Apply(opt *CmdOptions)

Apply assigns CmdName to given CmdOptions Receive CmdOptions

type CmdOptions

type CmdOptions struct {
	UseMetrics bool
	CmdName    string
}

CmdOptions encapsulates options for executing command

func (*CmdOptions) ApplyOptions

func (o *CmdOptions) ApplyOptions(opts []Options)

ApplyOptions applies given options for CmdOptions struct Receive list of options

type Executor

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

Executor is the implementation of CmdExecutor based on os/exec package

func NewExecutor

func NewExecutor(log *logrus.Logger) *Executor

NewExecutor is a constructor for executor

func (*Executor) RunCmd

func (e *Executor) RunCmd(cmd interface{}, opts ...Options) (string, string, error)

RunCmd runs specified command on OS Receives command as empty interface. It could be string or instance of exec.Cmd Returns stdout as string, stderr as string and golang error if something went wrong

func (*Executor) RunCmdWithAttempts

func (e *Executor) RunCmdWithAttempts(cmd interface{}, attempts int, timeout time.Duration, opts ...Options) (string, string, error)

RunCmdWithAttempts runs specified command on OS with given attempts and timeout between attempts Receives command as empty interface, It could be string or instance of exec.Cmd; number of attempts; timeout. Returns stdout as string, stderr as string and golang error if something went wrong

func (*Executor) SetLevel

func (e *Executor) SetLevel(level logrus.Level)

SetLevel sets logrus Level to Executor msgLevel field Receives logrus Level

type Options

type Options interface {
	Apply(*CmdOptions)
}

Options represents interface for applying options

type UseMetrics

type UseMetrics bool

UseMetrics represents options to use metrics in executor

func (UseMetrics) Apply

func (u UseMetrics) Apply(opt *CmdOptions)

Apply assigns UseMetrics to given CmdOptions Receive CmdOptions

Jump to

Keyboard shortcuts

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