command

package
v0.0.0-...-3f873ad Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2024 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Overview

Package command provide utilities around os/exec package

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrAlreadyStarted = errors.New("command: already started")
	ErrAlreadyWaited  = errors.New("command: already waited")
	ErrPromptAbort    = errors.New("command: aborted by prompt")
)

Functions

func CmdArgsFromString

func CmdArgsFromString(s string) ([]string, error)

CmdArgsFromString returns args for exec.Command from a string command 's' When string command 's' contains multiple commands,

exec.Command("/bin/sh", "-c", s)

else

exec.Command from shlex.Split(s)

func ShLimitCommands

func ShLimitCommands(l limits.T) string

ShLimitCommands provides ulimit commands for sh launcher max value of LimitVMem, LimitAs is used to set virtual memory limit

func WithArgs

func WithArgs(args []string) funcopt.O

WithArgs sets the process args[1:] from a string slice

func WithBufferedStderr

func WithBufferedStderr() funcopt.O

WithBufferedStderr activates the buffering of the lines emited by the process on stderr

func WithBufferedStdout

func WithBufferedStdout() funcopt.O

WithBufferedStdout activates the buffering of the lines emited by the process on stdout

func WithCWD

func WithCWD(cwd string) funcopt.O

func WithCommandLogLevel

func WithCommandLogLevel(l zerolog.Level) funcopt.O

WithCommandLogLevel show command name and args during Start

default zerolog.DebugLevel

func WithContext

func WithContext(ctx context.Context) funcopt.O

WithContext sets the command context

func WithEnv

func WithEnv(env []string) funcopt.O

func WithErrorExitCodeLogLevel

func WithErrorExitCodeLogLevel(l zerolog.Level) funcopt.O

WithErrorExitCodeLogLevel sets the level of the log entries for error exit code.

func WithGroup

func WithGroup(group string) funcopt.O

func WithIgnoredExitCodes

func WithIgnoredExitCodes(codes ...int) funcopt.O

WithIgnoredExitCodes set alternate list of successful exit codes.

exit codes are checked during Wait().
- default successful exit code is 0 when WithIgnoredExitCodes is not used
- Ignore all exit codes: WithIgnoredExitCodes()
- Accept 0, 1 or 6 exit code: WithIgnoredExitCodes(0, 1, 6)

func WithLogLevel

func WithLogLevel(l zerolog.Level) funcopt.O

WithLogLevel sets the level of the log entries.

func WithLogger

func WithLogger(l *plog.Logger) funcopt.O

WithLogger defines the Logger that will receive this pkg logs and process outputs

func WithName

func WithName(name string) funcopt.O

WithName sets the process args[0]

func WithOnStderrLine

func WithOnStderrLine(f func(string)) funcopt.O

func WithOnStdoutLine

func WithOnStdoutLine(f func(string)) funcopt.O

func WithPrompt

func WithPrompt(l *bufio.Reader) funcopt.O

WithLogger defines the Logger that will receive this pkg logs and process outputs

func WithStderrLogLevel

func WithStderrLogLevel(l zerolog.Level) funcopt.O

WithStderrLogLevel sets the level of the log entries coming from the process stderr If not set, stderr lines are not logged.

func WithStdoutLogLevel

func WithStdoutLogLevel(l zerolog.Level) funcopt.O

WithStdoutLogLevel sets the level of the log entries coming from the process stdout. If not set, stdout lines are not logged.

func WithTimeout

func WithTimeout(timeout time.Duration) funcopt.O

WithTimeout sets the max duration the process is allowed to run. After this duration, the process is killed and an error is reported.

func WithUser

func WithUser(user string) funcopt.O

func WithVarArgs

func WithVarArgs(args ...string) funcopt.O

WithVarArgs sets the process args[1:] from a variadic string slice

func WithVarEnv

func WithVarEnv(env ...string) funcopt.O

Types

type ErrExitCode

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

func (*ErrExitCode) Error

func (e *ErrExitCode) Error() string

func (*ErrExitCode) ExitCode

func (e *ErrExitCode) ExitCode() int

type T

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

func New

func New(opts ...funcopt.O) *T

func (*T) Cmd

func (t *T) Cmd() *exec.Cmd

func (*T) ExitCode

func (t *T) ExitCode() int

func (T) Output

func (t T) Output() ([]byte, error)

Output returns stdout results of command (meaningful after Wait() or Run()), command created without funcopt WithBufferedStdout() return nil valid results

func (*T) Run

func (t *T) Run() error

func (*T) Start

func (t *T) Start() (err error)

Start prepare command, then call underlying cmd.Start() it takes care of preparing logging, timeout, stdout and stderr watchers

func (T) Stderr

func (t T) Stderr() []byte

Stderr returns stderr results of command (meaningful after Wait() or Run()) command created without funcopt WithBufferedStderr() return nil

func (T) Stdout

func (t T) Stdout() []byte

Stdout returns stdout results of command (meaningful after Wait() or Run()), command created without funcopt WithBufferedStdout() return nil valid results

func (*T) String

func (t *T) String() string

func (*T) Wait

func (t *T) Wait() (err error)

Jump to

Keyboard shortcuts

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