sh

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2016 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Overview

nash provides the execution engine

Index

Constants

View Source
const (
	ESuccess    StatusCode = 0
	ENotFound              = 127
	ENotStarted            = 255
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AppendFn

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

func NewAppendFn

func NewAppendFn(env *Shell) *AppendFn

func (*AppendFn) ArgNames

func (appendfn *AppendFn) ArgNames() []string

func (*AppendFn) Name

func (appendfn *AppendFn) Name() string

func (*AppendFn) Results

func (appendfn *AppendFn) Results() sh.Obj

func (*AppendFn) SetArgs

func (appendfn *AppendFn) SetArgs(args []sh.Obj) error

func (*AppendFn) SetEnviron

func (appendfn *AppendFn) SetEnviron(env []string)

func (*AppendFn) SetStderr

func (appendfn *AppendFn) SetStderr(w io.Writer)

func (*AppendFn) SetStdin

func (appendfn *AppendFn) SetStdin(r io.Reader)

func (*AppendFn) SetStdout

func (appendfn *AppendFn) SetStdout(w io.Writer)

func (*AppendFn) Start

func (appendfn *AppendFn) Start() error

func (*AppendFn) Stderr

func (appendfn *AppendFn) Stderr() io.Writer

func (*AppendFn) Stdin

func (appendfn *AppendFn) Stdin() io.Reader

func (*AppendFn) Stdout

func (appendfn *AppendFn) Stdout() io.Writer

func (*AppendFn) StdoutPipe

func (appendfn *AppendFn) StdoutPipe() (io.ReadCloser, error)

func (*AppendFn) String

func (appendfn *AppendFn) String() string

func (*AppendFn) Wait

func (appendfn *AppendFn) Wait() error

type ChdirFn

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

func NewChdir

func NewChdir(env *Shell) *ChdirFn

func (*ChdirFn) ArgNames

func (chdir *ChdirFn) ArgNames() []string

func (*ChdirFn) Name

func (chdir *ChdirFn) Name() string

func (*ChdirFn) Results

func (chdir *ChdirFn) Results() sh.Obj

func (*ChdirFn) SetArgs

func (chdir *ChdirFn) SetArgs(args []sh.Obj) error

func (*ChdirFn) SetEnviron

func (chdir *ChdirFn) SetEnviron(env []string)

func (*ChdirFn) SetStderr

func (chdir *ChdirFn) SetStderr(w io.Writer)

func (*ChdirFn) SetStdin

func (chdir *ChdirFn) SetStdin(r io.Reader)

func (*ChdirFn) SetStdout

func (chdir *ChdirFn) SetStdout(w io.Writer)

func (*ChdirFn) Start

func (chdir *ChdirFn) Start() error

func (*ChdirFn) Stderr

func (chdir *ChdirFn) Stderr() io.Writer

func (*ChdirFn) Stdin

func (chdir *ChdirFn) Stdin() io.Reader

func (*ChdirFn) Stdout

func (chdir *ChdirFn) Stdout() io.Writer

func (*ChdirFn) StdoutPipe

func (chdir *ChdirFn) StdoutPipe() (io.ReadCloser, error)

func (*ChdirFn) String

func (chdir *ChdirFn) String() string

func (*ChdirFn) Wait

func (chdir *ChdirFn) Wait() error

type Cmd

type Cmd struct {
	*exec.Cmd
	// contains filtered or unexported fields
}

Cmd is a nash command. It has maps of input and output file descriptors that can be set by SetInputfd and SetOutputfd. This can be used to pipe execution of Cmd commands.

func NewCmd

func NewCmd(name string) (*Cmd, error)

func (*Cmd) Args

func (c *Cmd) Args() []ast.Expr

func (*Cmd) Results

func (c *Cmd) Results() sh.Obj

func (*Cmd) SetArgs

func (c *Cmd) SetArgs(nodeArgs []sh.Obj) error

func (*Cmd) SetEnviron

func (c *Cmd) SetEnviron(env []string)

func (*Cmd) SetStderr

func (c *Cmd) SetStderr(err io.Writer)

func (*Cmd) SetStdin

func (c *Cmd) SetStdin(in io.Reader)

func (*Cmd) SetStdout

func (c *Cmd) SetStdout(out io.Writer)

func (*Cmd) Start

func (c *Cmd) Start() error

func (*Cmd) Stderr

func (c *Cmd) Stderr() io.Writer

func (*Cmd) Stdin

func (c *Cmd) Stdin() io.Reader

func (*Cmd) Stdout

func (c *Cmd) Stdout() io.Writer

func (*Cmd) Wait

func (c *Cmd) Wait() error

type Env

type Env map[string]sh.Obj

Env is the environment map of lists

type Fns

type Fns map[string]sh.Fn

type LenFn

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

func NewLenFn

func NewLenFn(env *Shell) *LenFn

func (*LenFn) ArgNames

func (lenfn *LenFn) ArgNames() []string

func (*LenFn) Name

func (lenfn *LenFn) Name() string

func (*LenFn) Results

func (lenfn *LenFn) Results() sh.Obj

func (*LenFn) SetArgs

func (lenfn *LenFn) SetArgs(args []sh.Obj) error

func (*LenFn) SetEnviron

func (lenfn *LenFn) SetEnviron(env []string)

func (*LenFn) SetStderr

func (lenfn *LenFn) SetStderr(w io.Writer)

func (*LenFn) SetStdin

func (lenfn *LenFn) SetStdin(r io.Reader)

func (*LenFn) SetStdout

func (lenfn *LenFn) SetStdout(w io.Writer)

func (*LenFn) Start

func (lenfn *LenFn) Start() error

func (*LenFn) Stderr

func (lenfn *LenFn) Stderr() io.Writer

func (*LenFn) Stdin

func (lenfn *LenFn) Stdin() io.Reader

func (*LenFn) Stdout

func (lenfn *LenFn) Stdout() io.Writer

func (*LenFn) StdoutPipe

func (lenfn *LenFn) StdoutPipe() (io.ReadCloser, error)

func (*LenFn) String

func (lenfn *LenFn) String() string

func (*LenFn) Wait

func (lenfn *LenFn) Wait() error

type LogFn

type LogFn func(format string, args ...interface{})

LogFn is the logger type

func NewLog

func NewLog(ns string, enable bool) LogFn

NewLog creates a new nash logger

type Shell

type Shell struct {
	*sync.Mutex
	// contains filtered or unexported fields
}

Shell is the core data structure.

func NewShell

func NewShell() (*Shell, error)

NewShell creates a new shell object

func NewSubShell

func NewSubShell(name string, parent *Shell) (*Shell, error)

NewSubShell creates a nashell.Shell that inherits the parent shell stdin, stdout, stderr and mutex lock. Every variable and function lookup is done first in the subshell and then, if not found, in the parent shell recursively.

func (*Shell) Environ

func (shell *Shell) Environ() Env

func (*Shell) Exec

func (shell *Shell) Exec(path, content string) error

Exec executes the commands specified by string content

func (*Shell) ExecFile

func (shell *Shell) ExecFile(path string) error

Execute the nash file at given path

func (*Shell) ExecuteTree

func (shell *Shell) ExecuteTree(tr *ast.Tree) (sh.Obj, error)

func (*Shell) GetBuiltin

func (shell *Shell) GetBuiltin(name string) (sh.Fn, bool)

func (*Shell) GetFn

func (shell *Shell) GetFn(name string) (sh.Fn, bool)

func (*Shell) Getbindfn

func (shell *Shell) Getbindfn(cmdName string) (sh.Fn, bool)

func (*Shell) Getenv

func (shell *Shell) Getenv(name string) (sh.Obj, bool)

func (*Shell) Getvar

func (shell *Shell) Getvar(name string) (sh.Obj, bool)

func (*Shell) IsFn

func (shell *Shell) IsFn() bool

func (*Shell) Name

func (shell *Shell) Name() string

func (*Shell) Reset

func (shell *Shell) Reset()

Reset internal state

func (*Shell) SetDebug

func (shell *Shell) SetDebug(d bool)

SetDebug enable/disable debug in the shell

func (*Shell) SetEnviron

func (shell *Shell) SetEnviron(processEnv []string)

func (*Shell) SetIsFn

func (shell *Shell) SetIsFn(b bool)

func (*Shell) SetName

func (shell *Shell) SetName(a string)

func (*Shell) SetNashdPath

func (shell *Shell) SetNashdPath(path string)

SetNashdPath sets an alternativa path to nashd

func (*Shell) SetParent

func (shell *Shell) SetParent(a *Shell)

func (*Shell) SetRepr

func (shell *Shell) SetRepr(a string)

SetRepr set the string representation of the shell

func (*Shell) SetStderr

func (shell *Shell) SetStderr(err io.Writer)

SetStderr sets stderr for commands

func (*Shell) SetStdin

func (shell *Shell) SetStdin(in io.Reader)

SetStdin sets the stdin for commands

func (*Shell) SetStdout

func (shell *Shell) SetStdout(out io.Writer)

SetStdout sets stdout for commands

func (*Shell) SetTree

func (shell *Shell) SetTree(t *ast.Tree)

SetTree sets the internal tree of the interpreter. It's used for sub-shells like `fn`.

func (*Shell) Setbindfn

func (shell *Shell) Setbindfn(name string, value sh.Fn)

func (*Shell) Setenv

func (shell *Shell) Setenv(name string, value sh.Obj)

func (*Shell) Setvar

func (shell *Shell) Setvar(name string, value sh.Obj)

func (*Shell) Stderr

func (shell *Shell) Stderr() io.Writer

func (*Shell) Stdin

func (shell *Shell) Stdin() io.Reader

func (*Shell) Stdout

func (shell *Shell) Stdout() io.Writer

func (*Shell) String

func (shell *Shell) String() string

func (*Shell) Tree

func (shell *Shell) Tree() *ast.Tree

Tree returns the internal tree of the subshell.

func (*Shell) TriggerCTRLC

func (shell *Shell) TriggerCTRLC() error

type SplitFn added in v0.2.1

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

func NewSplitFn added in v0.2.1

func NewSplitFn(env *Shell) *SplitFn

func (*SplitFn) ArgNames added in v0.2.1

func (splitfn *SplitFn) ArgNames() []string

func (*SplitFn) Name added in v0.2.1

func (splitfn *SplitFn) Name() string

func (*SplitFn) Results added in v0.2.1

func (splitfn *SplitFn) Results() sh.Obj

func (*SplitFn) SetArgs added in v0.2.1

func (splitfn *SplitFn) SetArgs(args []sh.Obj) error

func (*SplitFn) SetEnviron added in v0.2.1

func (splitfn *SplitFn) SetEnviron(env []string)

func (*SplitFn) SetStderr added in v0.2.1

func (splitfn *SplitFn) SetStderr(w io.Writer)

func (*SplitFn) SetStdin added in v0.2.1

func (splitfn *SplitFn) SetStdin(r io.Reader)

func (*SplitFn) SetStdout added in v0.2.1

func (splitfn *SplitFn) SetStdout(w io.Writer)

func (*SplitFn) Start added in v0.2.1

func (splitfn *SplitFn) Start() error

func (*SplitFn) Stderr added in v0.2.1

func (splitfn *SplitFn) Stderr() io.Writer

func (*SplitFn) Stdin added in v0.2.1

func (splitfn *SplitFn) Stdin() io.Reader

func (*SplitFn) Stdout added in v0.2.1

func (splitfn *SplitFn) Stdout() io.Writer

func (*SplitFn) StdoutPipe added in v0.2.1

func (splitfn *SplitFn) StdoutPipe() (io.ReadCloser, error)

func (*SplitFn) String added in v0.2.1

func (splitfn *SplitFn) String() string

func (*SplitFn) Wait added in v0.2.1

func (splitfn *SplitFn) Wait() error

type StatusCode

type StatusCode uint8

type UserFn

type UserFn struct {
	*Shell // sub-shell
	// contains filtered or unexported fields
}

func NewUserFn

func NewUserFn(name string, parent *Shell) (*UserFn, error)

func (*UserFn) AddArgName

func (fn *UserFn) AddArgName(name string)

func (*UserFn) ArgNames

func (fn *UserFn) ArgNames() []string

func (*UserFn) Results

func (fn *UserFn) Results() sh.Obj

func (*UserFn) SetArgs

func (fn *UserFn) SetArgs(args []sh.Obj) error

func (*UserFn) Start

func (fn *UserFn) Start() error

func (*UserFn) StdoutPipe

func (fn *UserFn) StdoutPipe() (io.ReadCloser, error)

func (*UserFn) Wait

func (fn *UserFn) Wait() error

type Var

type Var Env

Jump to

Keyboard shortcuts

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