command

package
v1.7.4 Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2026 License: GPL-2.0 Imports: 12 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUnknownCommand   = errors.New("unknown command")
	ErrTooManyArguments = errors.New("too many arguments")
	ErrShouldExit       = errors.New("should exit")
	ErrNoCommand        = errors.New("no command provided")
)
View Source
var BUILTINS = make([]Command, 0)

Functions

This section is empty.

Types

type Cmd

type Cmd[T any] struct {
	ID       string
	Desc     string
	FlagFunc func(m Manager, stored *T, f *flag.FlagSet) error
	Execute  func(m Manager, stored T, args []string) error
	// contains filtered or unexported fields
}

func (*Cmd[T]) AddFlags

func (c *Cmd[T]) AddFlags(m Manager, f *flag.FlagSet) error

func (*Cmd[T]) Description

func (c *Cmd[T]) Description() string

func (*Cmd[T]) Exec

func (c *Cmd[T]) Exec(m Manager, args []string) error

func (*Cmd[T]) Name

func (c *Cmd[T]) Name() string

type Command

type Command interface {
	// How the command should be called from the command line
	Name() string

	// Execute the command
	// Any arguments not consumed by the flags will be passed here
	Exec(m Manager, args []string) error
}

type CommandAdder added in v1.7.2

type CommandAdder interface {
	// Add optional flags to the flagset
	AddFlags(m Manager, f *flag.FlagSet) error
}

type CommandDescriptor

type CommandDescriptor interface {
	Command
	Description() string
}

type CommandManager added in v1.7.2

type CommandManager struct {
	OUT io.Writer
	ERR io.Writer
	IN  *os.File
	Cmd Command
	Reg Registry
}

func (*CommandManager) Command added in v1.7.2

func (m *CommandManager) Command() Command

func (*CommandManager) Input added in v1.7.2

func (m *CommandManager) Input(question string) (string, error)

func (*CommandManager) Log added in v1.7.2

func (m *CommandManager) Log(message string)

func (*CommandManager) Logf added in v1.7.2

func (m *CommandManager) Logf(format string, args ...interface{})

func (*CommandManager) ProtectedInput added in v1.7.2

func (m *CommandManager) ProtectedInput(question string) (string, error)

func (*CommandManager) Registry added in v1.7.2

func (m *CommandManager) Registry() Registry

func (*CommandManager) Stderr added in v1.7.2

func (m *CommandManager) Stderr() io.Writer

func (*CommandManager) Stdin added in v1.7.2

func (m *CommandManager) Stdin() io.Reader

func (*CommandManager) Stdout added in v1.7.2

func (m *CommandManager) Stdout() io.Writer

type HelpCommand added in v1.7.2

type HelpCommand struct {
	ID   string
	Desc string
}

func (*HelpCommand) Description added in v1.7.2

func (c *HelpCommand) Description() string

func (*HelpCommand) Exec added in v1.7.2

func (c *HelpCommand) Exec(m Manager, args []string) error

func (*HelpCommand) Name added in v1.7.2

func (c *HelpCommand) Name() string

type Manager

type Manager interface {
	Log(message string)
	Logf(format string, args ...interface{})
	Stdout() io.Writer
	Stderr() io.Writer
	Stdin() io.Reader
	Input(question string) (string, error)
	ProtectedInput(question string) (string, error)
	Registry() Registry
	Command() Command
}

type Registry added in v1.6.7

type Registry interface {
	Name() string
	Which(cmdName string) (Command, bool)
	Register(cmd Command)
	Unregister(cmdName string) error
	Commands() []Command
	ExecCommand(args []string) error
	ExecCommandOpts(args []string, opts ...func(c *CommandManager)) error
}

func NewRegistry

func NewRegistry(flagsetName string, errorHandling flag.ErrorHandling) Registry

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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