term

package
v0.0.0-...-328052d Latest Latest
Warning

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

Go to latest
Published: May 14, 2023 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const Interrupt byte = 0x03

Variables

View Source
var ErrInterrupt = errors.New("interrupted")

Functions

func ParseInt

func ParseInt(s string) (val int, err error)

Types

type Arg

type Arg struct {
	Name string
	Desc string // Description of the argument
	Req  bool   // Mark as required
}

type CmdLine

type CmdLine struct {
	Args []string
	Env  []string
}

CmdLine represents a command line invocation.

func ParseCmdLine

func ParseCmdLine(cmdline string) (*CmdLine, error)

ParseCmdLine parses a command line string.

type Command

type Command struct {
	Name, Desc string

	Exec func(RunArgs) error
	// contains filtered or unexported fields
}

type Env

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

Env manages environment variables.

func NewEnv

func NewEnv() *Env

NewEnv creates a new environment.

func (*Env) Get

func (e *Env) Get(key string) (string, bool)

Get will return the value of the given key.

func (*Env) List

func (e *Env) List() []string

List will return a list of all keys for the current environment.

func (*Env) Set

func (e *Env) Set(key, value string)

Set will set the value of the given key.

func (*Env) SetParent

func (e *Env) SetParent(parent *Env)

SetParent will set the parent environment.

func (*Env) Unset

func (e *Env) Unset(key string)

Unset will remove the given key from the environment.

type Flag

type Flag struct {
	Name  string
	Env   string // Env var name
	Def   string // Default value
	Desc  string // Description of the flag
	Req   bool   // Mark as required
	Short rune
}

type Flags

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

func NewFlagSet

func NewFlagSet(cmd *CmdLine, env func(string) (string, bool)) *Flags

func (*Flags) Arg

func (fs *Flags) Arg(n int) string

func (*Flags) Args

func (fs *Flags) Args() []string

func (*Flags) Bool

func (fs *Flags) Bool(f Flag) *bool

func (*Flags) Byte

func (fs *Flags) Byte(f Flag) *byte

func (*Flags) Bytes

func (fs *Flags) Bytes(f Flag) *[]byte

func (*Flags) Enum

func (fs *Flags) Enum(f Flag, vals ...string) *string

func (*Flags) Example

func (fs *Flags) Example(cmdline, desc string)

func (*Flags) Int

func (fs *Flags) Int(f Flag) *int

func (*Flags) Parse

func (fs *Flags) Parse() error

func (*Flags) SetHelpParameters

func (fs *Flags) SetHelpParameters(s string)

SetHelpParameters sets the parameters for the usage output.

func (*Flags) String

func (fs *Flags) String(f Flag) *string

func (*Flags) Uint16

func (fs *Flags) Uint16(f Flag) *uint16

func (*Flags) UsageError

func (fs *Flags) UsageError(format string, a ...interface{}) error

type Prompt

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

func NewPrompt

func NewPrompt(w *ansi.Printer, prompt string) *Prompt

func (*Prompt) Draw

func (p *Prompt) Draw()

func (*Prompt) NextCommand

func (p *Prompt) NextCommand(c byte) (*CmdLine, error)

type RunArgs

type RunArgs struct {
	*Flags
	*ansi.Printer
	// contains filtered or unexported fields
}

func (*RunArgs) Get

func (ra *RunArgs) Get(k string) interface{}

func (*RunArgs) Input

func (ra *RunArgs) Input() <-chan byte

Input returns a rune reader for the shell.

Zero values should be ignored.

func (*RunArgs) Set

func (ra *RunArgs) Set(k string, v interface{})

func (*RunArgs) WaitForInterrupt

func (ra *RunArgs) WaitForInterrupt() bool

WaitForInterrupt will return true until CTRL+C is pressed.

type Shell

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

func NewRootShell

func NewRootShell(name, desc string, in io.Reader, out io.Writer) *Shell

func (*Shell) AddCommand

func (sh *Shell) AddCommand(name, desc string, exec func(RunArgs) error)

func (*Shell) AddCommands

func (sh *Shell) AddCommands(cmds ...Command)

func (*Shell) Get

func (sh *Shell) Get(k string) interface{}

Get will get a value from the shell or any of it's parents.

func (*Shell) NewSubShell

func (sh *Shell) NewSubShell(name, desc string, init func(RunArgs) error) *Shell

func (*Shell) Run

func (sh *Shell) Run() error

func (*Shell) Set

func (sh *Shell) Set(k string, v interface{})

Set will set a value in the shell for all it's children.

func (*Shell) SetNoExit

func (sh *Shell) SetNoExit(v bool)

type Ticker

type Ticker struct {
	C <-chan time.Time
	// contains filtered or unexported fields
}

func NewTicker

func NewTicker(dur time.Duration) *Ticker

func (*Ticker) Stop

func (t *Ticker) Stop()

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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