interp

package
v2.0.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2017 License: BSD-3-Clause Imports: 17 Imported by: 0

Documentation

Overview

Package interp implements an interpreter that executes shell programs. It aims to support POSIX, but its support is not complete yet. It also supports some Bash features.

This package is a work in progress and EXPERIMENTAL; its API is not subject to the 1.x backwards compatibility guarantee.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ExitCode

type ExitCode uint8

func (ExitCode) Error

func (e ExitCode) Error() string

type RunError

type RunError struct {
	Filename string
	syntax.Pos
	Text string
}

func (RunError) Error

func (e RunError) Error() string

type Runner

type Runner struct {
	// Env specifies the environment of the interpreter.
	// If Env is nil, Run uses the current process's environment.
	Env []string

	// Dir specifies the working directory of the command. If Dir is
	// the empty string, Run runs the command in the calling
	// process's current directory.
	Dir string

	// Params are the current parameters, e.g. from running a shell
	// file or calling a function. Accessible via the $@/$* family
	// of vars.
	Params []string

	Stdin  io.Reader
	Stdout io.Writer
	Stderr io.Writer

	// Context can be used to cancel the interpreter before it finishes
	Context context.Context
	// contains filtered or unexported fields
}

A Runner interprets shell programs. It cannot be reused once a program has been interpreted.

Note that writes to Stdout and Stderr may not be sequential. If you plan on using an io.Writer implementation that isn't safe for concurrent use, consider a workaround like hiding writes behind a mutex.

func (*Runner) FromArgs

func (r *Runner) FromArgs(args ...string) ([]string, error)

FromArgs populates the shell options and returns the remaining arguments. For example, running FromArgs("-e", "--", "foo") will set the "-e" option and return []string{"foo"}.

This is similar to what the interpreter's "set" builtin does.

func (*Runner) Reset

func (r *Runner) Reset() error

func (*Runner) Run

func (r *Runner) Run(node syntax.Node) error

Run starts the interpreter and returns any error.

Jump to

Keyboard shortcuts

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