command

package
v1.0.2-0...-0a9ac6a Latest Latest
Warning

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

Go to latest
Published: May 17, 2021 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrCommandNotFound = errors.New("command not found")

Functions

This section is empty.

Types

type ArgsProcessor

type ArgsProcessor interface {
	ProcessArgs(c *Command, args []string) []string
}

type ArgsProcessorFunc

type ArgsProcessorFunc func(cmd *Command, args []string) []string

ArgsProcessorFunc defines a functional implementation of ArgsProcessor.

func (ArgsProcessorFunc) ProcessArgs

func (f ArgsProcessorFunc) ProcessArgs(cmd *Command, args []string) []string

ArgsProcessorFunc implements ArgsProcessor.

type Command

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

func New

func New(params Params) *Command

func (Command) Desc

func (c Command) Desc() string

func (*Command) Exec

func (c *Command) Exec(ctx context.Context, args []string) error

func (Command) Name

func (c Command) Name() string

func (*Command) SetWriter

func (c *Command) SetWriter(w io.Writer)

func (Command) Usage

func (c Command) Usage(flags *pflag.FlagSet)

type FlagRegistry

type FlagRegistry interface {
	// RegisterFlags can be implemented to register custom flags.
	RegisterFlags(cmd *Command, flags *pflag.FlagSet)
}

FlagRegistry contains optional methods for parsing CLI arguments.

type FlagRegistryFunc

type FlagRegistryFunc func(cmd *Command, flags *pflag.FlagSet)

FlagRegistryFunc defines a functional implementation of FlagRegistry.

func (FlagRegistryFunc) RegisterFlags

func (f FlagRegistryFunc) RegisterFlags(cmd *Command, flags *pflag.FlagSet)

FlagRegistryFunc implements FlagRegistry.

type Handler

type Handler interface {
	// Handle receives the context and the arguments leftover from parsing.
	// When the first return value is non-nil and the error is nil, the value
	// will be passed as an argument to the subcommand.
	Handle(ctx context.Context, args []string) error
}

Handler is command line handler.

type HandlerFunc

type HandlerFunc func(ctx context.Context, args []string) error

HandlerFunc defines a functional implementation of Handler.

func (HandlerFunc) Handle

func (h HandlerFunc) Handle(ctx context.Context, args []string) error

Handle implements Handler interface.

type Params

type Params struct {
	Name              string
	Desc              string
	ArgsPreProcessor  ArgsProcessor
	ArgsPostProcessor ArgsProcessor
	FlagRegistry      FlagRegistry
	Handler           Handler
	SubCommands       []*Command
}

Jump to

Keyboard shortcuts

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