shellx

package
v0.28.0 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2024 License: GPL-3.0 Imports: 10 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

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

CopyFile copies [source] to [dest].

func Output

func Output(logger logmodel.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

func OutputCommandLine(logger logmodel.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

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

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

func OutputEx

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

OutputEx implements Output and OutputQuiet.

func OutputQuiet

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 v0.26.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 logmodel.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

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

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

func RunCommandLineQuiet

func RunCommandLineQuiet(cmdline string) error

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

func RunEx

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

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

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

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

func ParseCommandLine

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

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

func (*Argv) Append

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

Append appends arguments to the command line.

type Config

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

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

Config contains config for executing programs.

type Dependencies

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

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

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

Append appends an environment variable to the environment.

type StdlibDependencies

type StdlibDependencies struct{}

StdlibDependencies contains the stdlib implementation of the Dependencies.

func (*StdlibDependencies) CmdOutput

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

CmdOutput implements Dependencies.

func (*StdlibDependencies) CmdRun

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

CmdRun implements Dependencies.

func (*StdlibDependencies) LookPath

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