repl

package
v0.0.0-...-49a8380 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2019 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ActionFunc

type ActionFunc func([]string) (string, error)

ActionFunc defines the signature of an action associated with a command. Actions take on parameter, a slice of strings, representing the arguments passed to the command. Actions should return a string representing the result of the action, or an error if the action fails.

type Command

type Command struct {
	Name   string
	Action ActionFunc
	Usage  string
}

Command is a command that can be registered with the REPL. It consists of a name, an action that is run when the name is input to the REPL, and a usage string.

type REPL

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

REPL is a read-eval-print loop used to create a simple, minimalistic, easy-to-use command line interface for masterkey, with an automatic timeout that exits the program after a specified duration.

func New

func New(prompt string, timeout time.Duration) *REPL

New instantiates a new REPL using the provided `prompt` and `timeout`.

func (*REPL) AddCommand

func (r *REPL) AddCommand(cmd Command)

AddCommand registers the command provided in `cmd` with the REPL.

func (*REPL) Loop

func (r *REPL) Loop() error

Loop starts the Read-Eval-Print loop.

func (*REPL) OnStop

func (r *REPL) OnStop(sf func())

OnStop registers a function to be called when the REPL stops.

func (*REPL) Stop

func (r *REPL) Stop() error

Stop exits the REPL and runs the configured `OnStop` func, if one exists.

func (*REPL) Usage

func (r *REPL) Usage() string

Usage returns the usage for every command in the REPL.

Jump to

Keyboard shortcuts

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