command

package
v0.27.0 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Error          = errors.New("command error")
	ErrFlags       = errors.New("command flags error")
	ErrHasNoParent = errors.New("command has no parent command")
)

Functions

This section is empty.

Types

type Cmd

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

func Compile

func Compile(root *Command) (*Cmd, *logging.QueueLogger, error)

Command is building command chain from provided root command.

func (*Cmd) Categories

func (c *Cmd) Categories() map[string]string

func (*Cmd) ExecAfterAlways

func (c *Cmd) ExecAfterAlways(sess *session.Context, err error) error

func (*Cmd) ExecAfterFailure

func (c *Cmd) ExecAfterFailure(sess *session.Context, err error) error

func (*Cmd) ExecAfterSuccess

func (c *Cmd) ExecAfterSuccess(sess *session.Context) error

func (*Cmd) ExecBefore

func (c *Cmd) ExecBefore(sess *session.Context) (err error)

func (*Cmd) ExecDo

func (c *Cmd) ExecDo(sess *session.Context) (err error)

func (*Cmd) Flag

func (c *Cmd) Flag(name string) varflag.Flag

Flag looks up flag with given name and returns flags.Interface. If no flag was found empty bool flag will be returned. Instead of returning error you can check returned flags .IsPresent.

func (*Cmd) Flags

func (c *Cmd) Flags() []varflag.Flag

func (*Cmd) GetFlagSet

func (c *Cmd) GetFlagSet() varflag.Flags

func (*Cmd) GlobalFlags

func (c *Cmd) GlobalFlags() []varflag.Flag

func (*Cmd) HasBefore

func (c *Cmd) HasBefore() bool

func (*Cmd) Info

func (c *Cmd) Info() []string

func (*Cmd) IsImmediate

func (c *Cmd) IsImmediate() bool

func (*Cmd) IsRoot

func (c *Cmd) IsRoot() bool

func (*Cmd) IsWrapper

func (c *Cmd) IsWrapper() bool

func (*Cmd) Name

func (c *Cmd) Name() string

func (*Cmd) SharedFlags

func (c *Cmd) SharedFlags() []varflag.Flag

func (*Cmd) SkipSharedBeforeAction

func (c *Cmd) SkipSharedBeforeAction() bool

func (*Cmd) SubCommands

func (c *Cmd) SubCommands() []SubCmdInfo

func (*Cmd) Usage

func (c *Cmd) Usage() []string

type Command

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

func New

func New(s Config) *Command

func (*Command) AddInfo

func (c *Command) AddInfo(paragraph string) *Command

func (*Command) AfterAlways

func (c *Command) AfterAlways(a action.WithPrevErr) *Command

func (*Command) AfterFailure

func (c *Command) AfterFailure(a action.WithPrevErr) *Command

func (*Command) AfterSuccess

func (c *Command) AfterSuccess(a action.Action) *Command

func (*Command) Before

func (c *Command) Before(a action.WithArgs) *Command

func (*Command) DescribeCategory

func (c *Command) DescribeCategory(cat, desc string) *Command

func (*Command) Do

func (c *Command) Do(action action.WithArgs) *Command

func (*Command) Err

func (c *Command) Err() error

func (*Command) Usage

func (c *Command) Usage(usage string)

func (*Command) WithFlags

func (c *Command) WithFlags(ffns ...varflag.FlagCreateFunc) *Command

func (*Command) WithSubCommands added in v0.26.0

func (c *Command) WithSubCommands(cmds ...*Command) *Command

type Config

type Config struct {
	Name        settings.String `key:"name"`
	Usage       settings.String `key:"usage" mutation:"once"`
	Category    settings.String `key:"category"`
	Description settings.String `key:"description"`
	// MinArgs Minimum argument count for command
	MinArgs    settings.Uint `key:"min_args" default:"0" mutation:"once"`
	MinArgsErr settings.String
	// MaxArgs Maximum argument count for command
	MaxArgs    settings.Uint `key:"max_args" default:"0" mutation:"once"`
	MaxArgsErr settings.String
	// SharedBeforeAction share Before action for all its subcommands
	SharedBeforeAction settings.Bool `key:"shared_before_action" default:"false"`
	// Indicates that the command should be executed immediately, without waiting for the full runtime setup.
	Immediate settings.Bool `key:"immediate" default:"false"`
	// SkipSharedBefore indicates that the BeforeAlways any shared before actions provided
	// by parent commands should be skipped.
	SkipSharedBefore settings.Bool `key:"skip_shared_before" default:"false"`
}

func (Config) Blueprint

func (s Config) Blueprint() (*settings.Blueprint, error)

type SubCmdInfo

type SubCmdInfo struct {
	Name        string
	Description string
	Category    string
}

Jump to

Keyboard shortcuts

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