command

package
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2025 License: Apache-2.0 Imports: 9 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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