Documentation ¶
Index ¶
- Variables
- func SplitWords(line string) ([]string, error)
- func ToInt64(v interface{}) (int64, error)
- func ToString(v interface{}) string
- func ToUInt64(v interface{}) (uint64, error)
- func WithShell(ctx context.Context, sh *Shell) context.Context
- type Args
- func (a Args) Chan(i int) <-chan interface{}
- func (a Args) Get(i int, ctx ...context.Context) interface{}
- func (a Args) Int64(i int, ctx ...context.Context) (int64, error)
- func (a Args) String(i int, ctx ...context.Context) string
- func (a Args) Strings(ctx ...context.Context) []string
- func (a Args) UInt64(i int, ctx ...context.Context) (uint64, error)
- type Command
- type CommandInfo
- type HelpCommand
- func (c HelpCommand) Call(ctx context.Context, flags *pflag.FlagSet, args Args) (interface{}, error)
- func (c HelpCommand) CommandInfo() CommandInfo
- func (c HelpCommand) Flags() *pflag.FlagSet
- func (c HelpCommand) ShowCommand(ctx context.Context, args Args) error
- func (c HelpCommand) ShowIndex(ctx context.Context)
- type PS1
- type Scope
- type Shell
- func (sh *Shell) AddCommand(cmd Command)
- func (sh *Shell) Call(ctx context.Context, cmd Command, args []string) (interface{}, error)
- func (sh *Shell) Dump(retval interface{}) error
- func (sh *Shell) DumpError(err error)
- func (sh *Shell) Eval(ctx context.Context, line string) (interface{}, error)
- func (sh *Shell) Exec(ctx context.Context, words []string) (interface{}, error)
- func (sh *Shell) Lookup(args []string) (Command, []string, error)
- func (sh *Shell) PasswordPrompt(ps1 string) (string, error)
- func (sh *Shell) PopScope(s *Scope) *Scope
- func (sh *Shell) Prompt(ps1 string) (string, error)
- func (sh *Shell) PushScope() *Scope
- func (sh *Shell) Run(ctx context.Context) (rerr error)
- type Value
Constants ¶
This section is empty.
Variables ¶
var DefaultPS1 = NewPS1("~> ", "!> ")
The default value for Shell.PS1.
Functions ¶
func SplitWords ¶
Types ¶
type Command ¶
type Command interface { // Returns a CommandInfo struct describing this command. CommandInfo() CommandInfo // Returns flags for the command. If nil, arguments are passed verbatim. Flags() *pflag.FlagSet // Invokes the command. Returns a return value (if any), which will be printed. // In the future, it will be possible to assign return values to variables. Call(ctx context.Context, flags *pflag.FlagSet, args Args) (interface{}, error) }
type CommandInfo ¶
type HelpCommand ¶
type HelpCommand struct { }
func (HelpCommand) CommandInfo ¶
func (c HelpCommand) CommandInfo() CommandInfo
func (HelpCommand) Flags ¶
func (c HelpCommand) Flags() *pflag.FlagSet
func (HelpCommand) ShowCommand ¶
func (c HelpCommand) ShowCommand(ctx context.Context, args Args) error
func (HelpCommand) ShowIndex ¶
func (c HelpCommand) ShowIndex(ctx context.Context)
type Scope ¶
type Scope struct { Parent *Scope // Parent scope. Modal bool // A modal scope can be exitted with Ctrl+D. PS1 PS1 // PS1 associated with this scope; can be shadowed. // contains filtered or unexported fields }
A Scope represents a scope in the shell, holding variables and commands. Scopes can be stacked, in a reverse linked list structure, and shadow each other.
func (*Scope) Assign ¶
Sets a name to a value, attempting first to overwrite an existing instance of it, then resorting to creating it in the current scope.
type Shell ¶
type Shell struct { Scope *Scope // contains filtered or unexported fields }
func GetShell ¶
Returns the current shell. This is always available inside command handlers, or if you've previously called WithShell.
func (*Shell) AddCommand ¶
type Value ¶
type Value struct {
// contains filtered or unexported fields
}
Wraps a value received from the commandline or another argument. This exists to abstract away the difference between values and streams of values, allowing you to build pipeline constructions without needlessly complicating the simple (and much more common) use case of Just Passing A Dang String.
func (Value) Chan ¶
func (v Value) Chan() <-chan interface{}
Returns a channel for reading values. This will always return a channel - if the Value wraps a channel, that channel is returned, otherwise a buffered channel is returned that reads the wrapped value(s).