cmdutils

package
v1.17.0-beta18 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultCmder = &LocalCmder{}
)

Functions

func PrettyCommand

func PrettyCommand(name string, args ...string) string

PrettyCommand takes arguments identical to Cmder.Command, it returns a pretty printed command that could be pasted into a shell

Types

type Cmd

type Cmd interface {
	// Run executes the command (like os/exec.Cmd.Run)
	// It returns a *RunError if there is any error, nil otherwise
	Run() *RunError

	// WithEnv sets the Env variables for the Cmd
	// Each entry should be of the form "key=value"
	WithEnv(...string) Cmd

	// WithStdin sets the io.Reader used for stdin
	WithStdin(reader io.Reader) Cmd

	// WithStdout sets the io.Writer used for stdout
	WithStdout(io.Writer) Cmd

	// WithStderr sets the io.Reader used for stderr
	WithStderr(io.Writer) Cmd
}

Cmd abstracts over running a command somewhere

func Command

func Command(ctx context.Context, command string, args ...string) Cmd

Command is a convenience wrapper over DefaultCmder.Command

type Cmder

type Cmder interface {
	Command(ctx context.Context, name string, args ...string) Cmd
}

Cmder abstracts over creating commands

type LocalCmd

type LocalCmd struct {
	*exec.Cmd
}

LocalCmd wraps os/exec.Cmd, implementing the cmdutils.Cmd interface

func (*LocalCmd) Run

func (cmd *LocalCmd) Run() *RunError

Run runs the command If the returned error is non-nil, it should be of type *RunError

func (*LocalCmd) WithEnv

func (cmd *LocalCmd) WithEnv(env ...string) Cmd

WithEnv sets env

func (*LocalCmd) WithStderr

func (cmd *LocalCmd) WithStderr(w io.Writer) Cmd

WithStderr sets stderr

func (*LocalCmd) WithStdin

func (cmd *LocalCmd) WithStdin(r io.Reader) Cmd

WithStdin sets stdin

func (*LocalCmd) WithStdout

func (cmd *LocalCmd) WithStdout(w io.Writer) Cmd

WithStdout set stdout

type LocalCmder

type LocalCmder struct{}

LocalCmder is a factory for LocalCmd, implementing Cmder

func (*LocalCmder) Command

func (c *LocalCmder) Command(ctx context.Context, name string, arg ...string) Cmd

Command returns a Cmd which includes the running process's `Environment`

type RunError

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

RunError represents an error running a Cmd

func (*RunError) Cause

func (e *RunError) Cause() error

Cause mimics github.com/pkg/errors's Cause pattern for errors

func (*RunError) Error

func (e *RunError) Error() string

func (*RunError) OutputString

func (e *RunError) OutputString() string

func (*RunError) PrettyCommand

func (e *RunError) PrettyCommand() string

PrettyCommand pretty prints the command in a way that could be pasted into a shell

Jump to

Keyboard shortcuts

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