shelley

package
v0.0.0-...-074a105 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package shelley runs commands with behavior similar to a command line shell.

Index

Constants

This section is empty.

Variables

View Source
var DefaultContext = &Context{
	Stdin:       os.Stdin,
	Stdout:      os.Stdout,
	Stderr:      os.Stderr,
	DebugLogger: nil,
}

DefaultContext is the Context for commands created by the top level Command function.

Functions

func ExitIfError

func ExitIfError(err error)

ExitIfError exits the current process with a non-zero code if err is non-nil.

If err is an ExitError, the process will exit silently with the same code as the command that generated the error. Otherwise, the error will be logged with the log package and the process will exit with code 1.

This enables an extremely limited but easy to use form of error handling, roughly analogous to "set -e" in a shell script, but without the complex rules and exceptions that many "set -e" users (particularly this author) do not actually understand.

Types

type Cmd

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

Cmd represents a runnable command.

func Command

func Command(args ...string) *Cmd

Command initializes a new command using DefaultContext.

func (*Cmd) Env

func (c *Cmd) Env(name, value string) *Cmd

Env appends an environment value to the command.

The appended value overrides any value inherited from the current process or set by a previous Env call.

func (*Cmd) Run

func (c *Cmd) Run() error

Run runs the command and waits for it to complete.

type Context

type Context struct {
	// Stdin is the default source for stdin.
	Stdin io.Reader
	// Stdout is the default destination for stdout.
	Stdout io.Writer
	// Stderr is the default destination for stderr.
	Stderr io.Writer
	// DebugLogger logs all commands as they are executed, approximating the
	// behavior of "set -x" in a shell. Debug lines include environment variables
	// along with the exact arguments that a command was built with, with shell
	// quoting for all values. Aliases are not expanded.
	DebugLogger *log.Logger
}

Context provides default settings that affect the execution of commands.

func (*Context) Command

func (c *Context) Command(args ...string) *Cmd

Command initializes a new command that will run with the provided arguments.

The first argument is the name of the command to be run. If it contains no path separators, it will be resolved to a complete name using a PATH lookup.

type ExitError

type ExitError = *exec.ExitError

ExitError is the type of error returned by commands that completed with a non-zero exit code.

Jump to

Keyboard shortcuts

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