command

package
v0.100.5 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2025 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Error                = errors.New("command")
	ErrFlags             = fmt.Errorf("%w flags error", Error)
	ErrHasNoParent       = fmt.Errorf("%w has no parent command", Error)
	ErrCommandNotAllowed = fmt.Errorf("%w not allowed", Error)
	ErrNotImplemented    = fmt.Errorf("%w not implemented", Error)
)

Functions

func NotImplemented added in v0.100.0

func NotImplemented(msg string) error

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) CheckDisabled added in v0.100.0

func (c *Cmd) CheckDisabled(sess *session.Context) bool

func (*Cmd) Config added in v0.100.0

func (c *Cmd) Config() *settings.Profile

func (*Cmd) Disabled added in v0.100.0

func (c *Cmd) Disabled() bool

func (*Cmd) Err added in v0.100.0

func (c *Cmd) Err() error

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) (string, 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) Parent added in v0.100.0

func (c *Cmd) Parent() *Cmd

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(name string, cnf Config) *Command

func (*Command) AddInfo

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

func (*Command) AddUsage added in v0.100.0

func (c *Command) AddUsage(usage 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) Disable added in v0.100.0

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

func (*Command) Do

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

func (*Command) Err

func (c *Command) Err() error

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 {
	Usage            settings.String `key:"usage" mutation:"once"`
	HideDefaultUsage settings.Bool   `key:"hide_default_usage" default:"false"`
	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"`
	// Disabled indicates that the command should be disabled in the command list.
	Disabled settings.Bool `key:"disabled" default:"false" mutation:"mutable"`
	// FailDisabled indicates that the command should fail when disabled.
	// If Disable action is set, the command will fail with an error message returned by action.
	// If Disable action is not set, but Disabled is true, the command will fail with an error message ErrCommandNotAllowed.
	FailDisabled settings.Bool `key:"fail_disabled" default:"false"`
}

func (Config) Blueprint

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

type SubCmdInfo

type SubCmdInfo struct {
	Name        string
	Description string
	Category    string
	Disabled    bool
	// contains filtered or unexported fields
}

Jump to

Keyboard shortcuts

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