commands

package
v0.16.5 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2023 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Execute

func Execute(args []string) error

func IsCommandError

func IsCommandError(err error) bool

IsCommandError reports whether any error in err's tree matches CommandError.

Types

type CommandError

type CommandError struct {
	Err error
}

CommandError is returned when a command fails because of a user error (unknown command, invalid flag etc.). All other errors comes from the execution of the command.

func (*CommandError) Error

func (e *CommandError) Error() string

Error implements error.

func (*CommandError) Is

func (*CommandError) Is(e error) bool

Is reports whether e is of type *CommandError.

type Commandeer

type Commandeer struct {
	Command      Commander
	CobraCommand *cobra.Command

	Root   *Commandeer
	Parent *Commandeer
	// contains filtered or unexported fields
}

Commandeer holds the state of a command and its subcommands.

type Commander

type Commander interface {
	Name() string

	Use() string

	// Init is called when the cobra command is created.
	// This is where the flags, short and long description etc. can be added.
	Init(*Commandeer) error

	// Args the command args
	Args(ctx context.Context, cd *Commandeer, args []string) error

	// PreRun called on all ancestors and the executing command itself, before execution, starting from the root.
	// This is the place to evaluate flags and set up the this Commandeer.
	// The runner Commandeer holds the currently running command, which will be PreRun last.
	PreRun(this, runner *Commandeer) error

	// Run the command execution.
	Run(ctx context.Context, cd *Commandeer, args []string) error

	// Commands returns the sub commands, if any.
	Commands() []Commander
}

Commander is the interface that must be implemented by all commands.

type Exec

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

func New

func New(rootCmd Commander) (*Exec, error)

func (*Exec) Execute

func (r *Exec) Execute(ctx context.Context, args []string) (*Commandeer, error)

Jump to

Keyboard shortcuts

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