command

package
v0.0.0-...-27fe9b7 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2021 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var CommandRegex = regexp.MustCompile(`(?m)("[^"]+"|[^\s"]+)`)

Functions

This section is empty.

Types

type Command

type Command interface {
	Execute(logger.Logger) error
	Info() CommandInfo
}

type CommandInfo

type CommandInfo struct {
	Name        string
	Description string
	Usage       string
}

type Help

type Help struct {
	Map Map
}

func (Help) Execute

func (h Help) Execute(logger logger.Logger) error

func (Help) Info

func (h Help) Info() CommandInfo

type Map

type Map map[string]Command

func NewMap

func NewMap() Map

func (Map) Get

func (m Map) Get(name string) (Command, error)

Get returns the given command registered to this map by its name. ex `m.Get("help")`

func (Map) Register

func (m Map) Register(name string, cmd Command, override bool)

Register adds the given Command to by name to the Map with a option to override if the said command already exists.

func (Map) Unregister

func (m Map) Unregister(name string)

Unregister removes the given command by its name from the command map.

type Processor

type Processor struct {
	Map    Map
	On     func(cmd Command)
	Logger logger.Logger
	// contains filtered or unexported fields
}

func NewProcessor

func NewProcessor(logger logger.Logger, callback func(cmd Command)) Processor

func (Processor) RegisterDefaults

func (p Processor) RegisterDefaults()

func (Processor) StartProcessing

func (p Processor) StartProcessing(in *os.File)

StartProcessing starts the command processor reading from the given std in (*io.File in golang terms.)

func (Processor) StopProcessing

func (p Processor) StopProcessing()

StopProcessing stops the command processor from occupying the stdin and will stop all future command execution.

Jump to

Keyboard shortcuts

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