command

package
v1.6.9 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2024 License: GPL-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUnknownCommand   = errors.New("unknown command")
	ErrTooManyArguments = errors.New("too many arguments")
	ErrNoCommand        = errors.New("no command provided")
)

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

	// Add optional flags to the flagset
	AddFlags(m Manager, f *flag.FlagSet) error

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

type CommandDescriptor

type CommandDescriptor interface {
	Command
	Description() 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)
	Command() Command
}

type Registry added in v1.6.7

type Registry interface {
	Register(cmd Command)
	Commands() []Command
	ExecCommand(args []string) error
}

func NewRegistry

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

Jump to

Keyboard shortcuts

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