command

package
v0.0.0-...-71e9170 Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2023 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrDuplicateCommand = errors.New("Duplicate command")

ErrDuplicateCommand is returned when two commands have the same name

Functions

func Register

func Register(command Command) error

Register adds the Command to the command list

func Shutdown

func Shutdown(w io.Writer)

Shutdown executes shutdown for all commands

func Startup

func Startup(w io.Writer)

Startup executes Startup for all commands

Types

type Base

type Base struct {
	Name, Help string
	Action     func(input io.Reader, output io.Writer, args ...string) (exit bool)
}

Base is a basic Command that runs a closure

func (Base) GetHelp

func (b Base) GetHelp() string

GetHelp returns the Help

func (Base) GetName

func (b Base) GetName() string

GetName returns the Name

func (Base) Run

func (b Base) Run(input io.Reader, output io.Writer, args ...string) (exit bool)

Run calls the closure

func (Base) Shutdown

func (b Base) Shutdown(w io.Writer) error

Shutdown does nothing

func (Base) Startup

func (b Base) Startup(w io.Writer) error

Startup does nothing

func (Base) String

func (b Base) String() string

type Command

type Command interface {
	Startup(w io.Writer) error
	Shutdown(w io.Writer) error
	GetName() string
	GetHelp() string
	Run(input io.Reader, output io.Writer, args ...string) (exit bool)
}

Command represents a terminal command

func GetCommand

func GetCommand(name string) Command

GetCommand returns the command with the given name

Jump to

Keyboard shortcuts

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