import "github.com/egdaemon/eg/runtime/wasi/shell"
const (
DefaultTimeout = 5 * time.Minute
)
func Op(cmds ...Command) eg.OpFn
Convience function for running a set of commands as an operation.
func Parallel(cmds ...Command) eg.OpFn
Convience function for running a set of commands in parallel as an operation.
func Run(ctx context.Context, cmds ...Command) error
Run the provided commands using the operation.
type Command struct {
// contains filtered or unexported fields
}
func Env() Command
Env creates a runtime command pre-populated with the current process environment.
func New(cmd string) Command
New create a new command with reasonable defaults. defaults:
timeout: 5 minutes.
func NewLocal() Command
NewLocal creates a command that executes locally via bash without the WASI runtime or sudo. Useful for testing.
func Newf(cmd string, options ...any) Command
Newf provides a simple printf form of creating commands.
func Runtime() Command
Runtime creates a Command with no specified command to run. and can be used as a template:
tmp := shell.Runtime().Environ("FOO", "BAR")
shell.Run(
tmp.New("ls -lha"),
tmp.New("echo hello world"),
)
func (t Command) As(u string) Command
convience function that sets both user and group to the provided value.
func (t Command) Attempts(a int16) Command
number of attempts to make before giving up.
func (t Command) Colors(enabled bool) Command
enable or disable colorized log output (warnings on retries, errors on failure). default is enabled.
func (t Command) Debug() Command
debug a command
func (t Command) Directory(d string) Command
directory to run the command in. must be a relative path.
func (t Command) Environ(k string, v any) Command
append a specific key/value environment variable.
func (t Command) EnvironFrom(environ ...string) Command
append a set of environment variables in the form KEY=VALUE to the environment.
func (t Command) Group(g string) Command
group to run the command as
func (t Command) Lenient(d bool) Command
directory to run the command in. must be a relative path.
func (t Command) MaybeDebug(b bool) Command
func (t Command) MaybePrivileged(b bool) Command
specialized for As("root") which runs the command as root when true. allows conditional flagging privileged. when false the command is unchanged.
func (t Command) New(cmd string) Command
New clone the current command configuration and replace the command that will be executed.
func (t Command) Newf(cmd string, options ...any) Command
Newf provides a simple printf form of creating commands.
func (t Command) Privileged() Command
specialized for As("root") which runs the command as root.
func (t Command) Retry(l *rate.Limiter) Command
limits how quickly attempts are retried, see Attempts. the limiter must not be nil.
func (t Command) Silent(d bool) Command
silence the warnings logged when a failure is ignored by Lenient or before a retry, see Attempts. the output of the command itself is not affected, and a failure that is returned is still reported.
func (t Command) Timeout(d time.Duration) Command
maximum duration for a command to run. default is 5 minutes.
func (t Command) UnsafeEntrypoint(e entrypoint) Command
Internal use only not under compatability promises.
func (t Command) UnsafeExec(e Execer) Command
func (t Command) User(u string) Command
user to run the command as
type Execer func(ctx context.Context, dir string, environ []string, cmd string, args []string) error
type Recorder struct {
// contains filtered or unexported fields
}
func NewRecorder(cmd *Command) *Recorder
creates a recorder that allows for generating string representations of commands for tests.
func (t *Recorder) Hijack(cmd *Command) error
func (t *Recorder) Record(ctx context.Context, dir string, environ []string, cmd string, args []string) error
func (t *Recorder) Result() string
func (t *Recorder) Results() []string