shx

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2025 License: Apache-2.0 Imports: 12 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

View Source
var HomeDir = sync.OnceValue(func() string {
	return internal.Must(os.UserHomeDir())
})

Functions

func PrettyPath

func PrettyPath(path string) string

Types

type Cmd

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

func New

func New(
	name string,
	args ...string,
) *Cmd

func (*Cmd) Run

func (c *Cmd) Run(ctx context.Context) (*Result, error)

Run runs the command and waits for it to finish.

If the command fails to start, it returns a nil Result and the error. If the command starts but exits with an error code, the error will be in the Result. This behavior can be overridden with an option to copy the Result error to the top level error, if the caller doesn't care about the distinction.

func (*Cmd) With

func (c *Cmd) With(opts ...Option) *Cmd

With applies options to the command.

It panics if Run has already been called.

type Option

type Option interface {
	// contains filtered or unexported methods
}

func CaptureCombined

func CaptureCombined() Option

func CaptureError added in v0.9.0

func CaptureError() Option

func CaptureOutput

func CaptureOutput() Option

func FeedStdin

func FeedStdin(in io.Reader) Option

FeedStdin sets the command's Stdin to the provided io.Reader.

The caller is responsible for closing the reader if necessary after the command completes.

func PassOutput

func PassOutput() Option

PassOutput sets the command's Stdout and Stderr to os.Stdout and os.Stderr respectively, and clears any prior capture configuration.

func PassStderr

func PassStderr() Option

PassStderr sets the command's Stderr to os.Stderr and clears any prior capture configuration.

func PassStdin

func PassStdin() Option

PassStdin sets the command's Stdin to os.Stdin.

func PassStdio

func PassStdio() Option

func PassStdout

func PassStdout() Option

PassStdout sets the command's Stdout to os.Stdout and clears any prior capture configuration.

func WithCombinedError

func WithCombinedError() Option

WithCombinedError changes the behavior of Run to return all errors in the error return, instead of only returning errors starting the process there, and errors from the process in the Result.

func WithCwd

func WithCwd(path string) Option

func WithEnv added in v0.8.0

func WithEnv(key, value string) Option

func WithSudo

func WithSudo(purpose string) Option

func WithSudoUser

func WithSudoUser(user, purpose string) Option

func WithUmask added in v0.7.0

func WithUmask(umask os.FileMode) Option

type Result

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

func Run

func Run(
	ctx context.Context,
	cmdAndArgs []string,
	opts ...Option,
) (*Result, error)

func (*Result) Close

func (r *Result) Close() error

Close releases any resources associated with the result of running a command.

If no output capture was enabled, it is safe to skip calling this.

func (*Result) Err

func (r *Result) Err() error

func (*Result) Stderr

func (r *Result) Stderr() io.Reader

Stderr returns a reader over the captured stderr output.

If stderr was not captured, or was streamed to a custom Writer, this returns nil.

func (*Result) Stdout

func (r *Result) Stdout() io.Reader

Stdout returns a reader over the captured stdout output.

If stdout was not captured, or was streamed to a custom Writer, this returns nil.

Jump to

Keyboard shortcuts

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