shell

package
v0.0.0-...-c0b29db Latest Latest
Warning

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

Go to latest
Published: May 2, 2024 License: BSD-3-Clause Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var GlobUseSlash = false
View Source
var LastErrorLevel int
View Source
var LookCurdirOrder = nodos.LookCurdirFirst
View Source
var NoClobber = false
View Source
var OnCommandNotFound = func(ctx context.Context, cmd *Cmd, err error) error {
	err = &_CommandNotFound{cmd.args[0], err}
	return err
}
View Source
var PercentFunc = map[string]func() string{
	"CD": func() string {
		wd, err := os.Getwd()
		if err == nil {
			return wd
		}
		return ""
	},
	"ERRORLEVEL": func() string {
		return fmt.Sprintf("%d", LastErrorLevel)
	},
	"DATE": func() string {
		s, err := nodos.TimeFormatOsLayout(time.Now())
		if err != nil {
			return err.Error()
		}
		return s
	},
	"TIME": func() string {
		return time.Now().Format("15:04:05.00")
	},
}
View Source
var PostExecHook func(context.Context, *Cmd)
View Source
var PreExecHook func(context.Context, *Cmd)
View Source
var TildeExpansion = true
View Source
var UseSourceRunBatch = true
View Source
var WildCardExpansionAlways = false

Functions

func Message

func Message(format string, a ...interface{})

func OurGetEnv

func OurGetEnv(name string) (string, bool)

func Parse

func Parse(stream Stream, text string) ([][]*_Statement, error)

Parse parses the string and make Statement objects.

func Quote

func Quote(src string) string

func ReplaceIgnoreCase

func ReplaceIgnoreCase(s, old, new string) string

ReplaceIgnoreCase works like strings.Replace but ignores cases.

Types

type AlreadyReportedError

type AlreadyReportedError struct {
	Err error
}

func (AlreadyReportedError) Error

func (AlreadyReportedError) Error() string

type ArgsHookT

type ArgsHookT func(ctx context.Context, sh *Shell, args, rawargs []string) ([]string, []string, error)

func SetArgsHook

func SetArgsHook(_argsHook ArgsHookT) (rv ArgsHookT)

type BufStream

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

func (*BufStream) Add

func (bufStream *BufStream) Add(line string)

func (*BufStream) DisableHistory

func (*BufStream) DisableHistory(value bool) bool

func (*BufStream) ReadLine

func (bufStream *BufStream) ReadLine(c context.Context) (context.Context, string, error)

func (*BufStream) SetPos

func (bufStream *BufStream) SetPos(n int) error

type CloneCloser

type CloneCloser interface {
	Clone(context.Context) (context.Context, CloneCloser, error)
	Close() error
}

type Cmd

type Cmd struct {
	Shell

	UseShellExecute bool
	Closers         []io.Closer

	OnBackExec func(int)
	OnBackDone func(int)
	// contains filtered or unexported fields
}

func (*Cmd) Arg

func (cmd *Cmd) Arg(n int) string

func (*Cmd) Args

func (cmd *Cmd) Args() []string

func (*Cmd) Close

func (cmd *Cmd) Close()

func (*Cmd) DumpEnv

func (cmd *Cmd) DumpEnv() []string

func (*Cmd) FullPath

func (cmd *Cmd) FullPath() string

func (*Cmd) Getenv

func (cmd *Cmd) Getenv(key string) string

func (*Cmd) RawArg

func (cmd *Cmd) RawArg(n int) string

func (*Cmd) RawArgs

func (cmd *Cmd) RawArgs() []string

func (*Cmd) SetArgs

func (cmd *Cmd) SetArgs(s []string)

func (*Cmd) SetRawArgs

func (cmd *Cmd) SetRawArgs(s []string)

func (*Cmd) Setenv

func (cmd *Cmd) Setenv(key, val string)

func (*Cmd) Spawnvp

func (cmd *Cmd) Spawnvp(ctx context.Context) (int, error)

type CmdSeeker

type CmdSeeker struct {
	PlainHistory []string
	Pointer      int
}

type CmdStreamFile

type CmdStreamFile struct {
	CmdSeeker
	Scanner *bufio.Scanner
}

func NewCmdStreamFile

func NewCmdStreamFile(r io.Reader) *CmdStreamFile

func (*CmdStreamFile) DisableHistory

func (*CmdStreamFile) DisableHistory(value bool) bool

func (*CmdStreamFile) ReadLine

func (stream *CmdStreamFile) ReadLine(ctx context.Context) (context.Context, string, error)

type History

type History interface {
	Len() int
	DumpAt(n int) string
	IgnorePush(newvalue bool) bool
}

type HookT

type HookT func(context.Context, *Cmd) (int, bool, error)

func SetHook

func SetHook(_hook HookT) (rv HookT)

type NulStream

type NulStream struct{}

NulStream is the null implementation for the interface Stream.

func (*NulStream) DisableHistory

func (stream *NulStream) DisableHistory(value bool) bool

DisableHistory do nothing.

func (*NulStream) ReadLine

func (stream *NulStream) ReadLine(ctx context.Context) (context.Context, string, error)

ReadLine always returns "" and io.EOF.

type Shell

type Shell struct {
	Stream
	History  History
	LineHook func(context.Context, *Cmd) (int, bool, error)
	ArgsHook func(context.Context, *Shell, []string, []string) ([]string, []string, error)

	Stdio   [3]*os.File
	Console io.Writer

	IsBackGround bool
	// contains filtered or unexported fields
}

func New

func New() *Shell

func (*Shell) Close

func (sh *Shell) Close()

func (*Shell) Command

func (sh *Shell) Command() *Cmd

func (*Shell) Err

func (sh *Shell) Err() io.Writer

func (*Shell) ForEver

func (sh *Shell) ForEver(ctx context.Context, stream Stream) error

ForEver executes commands from `stream` until EOF are found.

func (*Shell) GetHistory

func (sh *Shell) GetHistory() History

func (*Shell) In

func (sh *Shell) In() io.Reader

func (*Shell) Interpret

func (sh *Shell) Interpret(ctx context.Context, text string) (errorlevel int, finalerr error)

func (*Shell) Loop

func (sh *Shell) Loop(ctx0 context.Context, stream Stream) (int, error)

Loop executes commands from `stream` until any errors are found.

func (*Shell) Out

func (sh *Shell) Out() io.Writer

func (*Shell) ReadCommand

func (sh *Shell) ReadCommand(ctx context.Context) (context.Context, string, error)

ReadCommand reads completed one command from `stream`.

func (*Shell) SetTag

func (sh *Shell) SetTag(tag CloneCloser)

func (*Shell) Source

func (sh *Shell) Source(ctx context.Context, fname string) error

func (*Shell) Spawnlp

func (sh *Shell) Spawnlp(ctx context.Context, args, rawargs []string) (int, error)

func (*Shell) Spawnlpe

func (sh *Shell) Spawnlpe(ctx context.Context, args, rawargs []string, env map[string]string) (int, error)

func (*Shell) Tag

func (sh *Shell) Tag() CloneCloser

func (*Shell) Term

func (sh *Shell) Term() io.Writer

type Stream

type Stream interface {
	ReadLine(context.Context) (context.Context, string, error)
	DisableHistory(value bool) bool
}

Stream is the inteface which can read command-line

Jump to

Keyboard shortcuts

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