shellx

package
v3.19.0 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2023 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Overview

Package shellx helps to write shell-like Go code.

Index

Constants

View Source
const (
	// FlagShowStdoutStderr enables connecting the child's stdout and stderr
	// to the current program's stdout and stderr.
	FlagShowStdoutStderr = 1 << iota
)

Variables

View Source
var ErrNoCommandToExecute = errors.New("shellx: no command to execute")

ErrNoCommandToExecute means that the command line is empty.

Functions

func CopyFile added in v3.17.0

func CopyFile(source, dest string, perms fs.FileMode) error

CopyFile copies [source] to [dest].

func Output added in v3.17.0

func Output(logger model.Logger, command string, args ...string) ([]byte, error)

Output is like OutputQuiet except that it logs the command to be executed and the environment variables specific to this command.

func OutputCommandLine added in v3.17.0

func OutputCommandLine(logger model.Logger, cmdline string) ([]byte, error)

OutputCommandLine is like OutputCommandLineQuiet but logs the command to execute as well as the command-specific environment variables.

func OutputCommandLineQuiet added in v3.17.0

func OutputCommandLineQuiet(cmdline string) ([]byte, error)

OutputCommandLineQuiet is like OutputQuiet but takes a command line as argument.

func OutputEx added in v3.17.0

func OutputEx(config *Config, argv *Argv, envp *Envp) ([]byte, error)

OutputEx implements Output and OutputQuiet.

func OutputQuiet added in v3.17.0

func OutputQuiet(command string, args ...string) ([]byte, error)

OutputQuiet is like RunQuiet except that, in case of success, it captures the standard output and returns it to the caller.

func QuotedCommandLineUnsafe added in v3.19.0

func QuotedCommandLineUnsafe(command string, args ...string) string

QuotedCommandLineUnsafe returns a quoted command line. This function is unsafe and SHOULD only be used to produce a nice output.

func Run

func Run(logger model.Logger, command string, args ...string) error

Run is like RunQuiet except that it also logs the command to exec, the environment variables specific to this command, the text logged to stdout and stderr.

func RunCommandLine added in v3.17.0

func RunCommandLine(logger model.Logger, cmdline string) error

RunCommandLine is like RunCommandLineQuiet but logs the command to execute as well as the command-specific environment variables.

func RunCommandLineQuiet added in v3.17.0

func RunCommandLineQuiet(cmdline string) error

RunCommandLineQuiet is like RunQuiet but takes a command line as argument.

func RunEx added in v3.17.0

func RunEx(config *Config, argv *Argv, envp *Envp) error

RunEx implements Run and RunQuiet.

func RunQuiet

func RunQuiet(command string, args ...string) error

RunQuiet runs the given command without emitting any output.

Types

type Argv added in v3.17.0

type Argv struct {
	// P is the MANDATORY program to execute.
	P string

	// V contains the OPTIONAL arguments.
	V []string
}

Argv contains the complete argv.

func NewArgv added in v3.17.0

func NewArgv(command string, args ...string) (*Argv, error)

NewArgv creates a new Argv from the given command and arguments.

func ParseCommandLine added in v3.17.0

func ParseCommandLine(cmdline string) (*Argv, error)

ParseCommandLine creates an instance of Argv from the given command line.

func (*Argv) Append added in v3.17.0

func (a *Argv) Append(args ...string)

Append appends arguments to the command line.

type Config added in v3.17.0

type Config struct {
	// Logger is the OPTIONAL logger to use.
	Logger model.Logger

	// Flags contains OPTIONAL binary flags to configure the program.
	Flags int64
}

Config contains config for executing programs.

type Dependencies added in v3.17.0

type Dependencies interface {
	// CmdOutput is equivalent to calling c.Output.
	CmdOutput(c *execabs.Cmd) ([]byte, error)

	// CmdRun is equivalent to calling c.Run.
	CmdRun(c *execabs.Cmd) error

	// LookPath is equivalent to calling execabs.LookPath.
	LookPath(file string) (string, error)
}

Dependencies is the library on which this package depends.

var Library Dependencies = &StdlibDependencies{}

Library contains the default dependencies.

type Envp added in v3.17.0

type Envp struct {
	// V contains the OPTIONAL environment variables to add to the current
	// environment when we're executing commands.
	V []string
}

Envp is the environment in which we execute commands.

func (*Envp) Append added in v3.17.0

func (e *Envp) Append(key, value string)

Append appends an environment variable to the environment.

type StdlibDependencies added in v3.17.0

type StdlibDependencies struct{}

StdlibDependencies contains the stdlib implementation of the Dependencies.

func (*StdlibDependencies) CmdOutput added in v3.17.0

func (*StdlibDependencies) CmdOutput(c *execabs.Cmd) ([]byte, error)

CmdOutput implements Dependencies.

func (*StdlibDependencies) CmdRun added in v3.17.0

func (*StdlibDependencies) CmdRun(c *execabs.Cmd) error

CmdRun implements Dependencies.

func (*StdlibDependencies) LookPath added in v3.17.0

func (*StdlibDependencies) LookPath(file string) (string, error)

LookPath implements Dependencies.

Directories

Path Synopsis
Package shellxtesting supports shellx testing.
Package shellxtesting supports shellx testing.

Jump to

Keyboard shortcuts

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