command

package
v1.4.10 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2023 License: Apache-2.0 Imports: 4 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Action

type Action func(v Value) error

type CmdConfig

type CmdConfig struct {
	// The name of the command
	Name string
	// A list of aliases for the command
	Aliases []string
	// A short description of the usage of this command
	Usage string
	// Custom text to show on USAGE section of help
	UsageText string
	// A longer explanation of how the command works
	Description string
	// A short description of the arguments of this command
	ArgsUsage string
	// The category the command is part of
	Category string
	// Treat all flags as normal arguments if true
	SkipFlagParsing bool
	// Skip argument reordering which attempts to move flags before arguments,
	// but only works if all flags appear after all arguments. This behavior was
	// removed n version 2 since it only works under specific conditions so we
	// backport here by exposing it as an option for compatibility.
	SkipArgReorder bool
	// Boolean to hide built-in help command
	HideHelp bool
	// Boolean to hide this command from help or completion
	Hidden bool
	// Boolean to enable short-option handling so user can combine several
	// single-character bool arguments into one
	// i.e. foobar -o -v -> foobar -ov
	UseShortOptionHandling bool

	// Full name of command for help, defaults to full command name, including parent commands.
	HelpName string

	// CustomHelpTemplate the text template for the command help topic.
	// cli.go uses text/template to render templates. You can
	// render custom help text by setting this variable.
	CustomHelpTemplate string
}

type CmdOption

type CmdOption func(config *CmdConfig)

func WithAliases

func WithAliases(aliases []string) CmdOption

func WithArgsUsage

func WithArgsUsage(argsUsage string) CmdOption

func WithCategory

func WithCategory(category string) CmdOption

func WithCustomHelpTemplate

func WithCustomHelpTemplate(customHelpTemplate string) CmdOption

func WithDescription

func WithDescription(description string) CmdOption

func WithHelpName

func WithHelpName(helpName string) CmdOption

func WithHidden

func WithHidden(hidden bool) CmdOption

func WithHideHelp

func WithHideHelp(hideHelp bool) CmdOption

func WithName

func WithName(name string) CmdOption

func WithSkipArgReorder

func WithSkipArgReorder(skipArgReorder bool) CmdOption

func WithSkipFlagParsing

func WithSkipFlagParsing(skipFlagParsing bool) CmdOption

func WithUsage

func WithUsage(usage string) CmdOption

func WithUsageText

func WithUsageText(usageText string) CmdOption

func WithUseShortOptionHandling

func WithUseShortOptionHandling(useShortOptionHandling bool) CmdOption

type Command

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

func NewCommand

func NewCommand(options ...CmdOption) *Command

func NewCommandWithConfig

func NewCommandWithConfig(config CmdConfig) *Command

func (*Command) AddSubCommand

func (cmd *Command) AddSubCommand(subCommand *Command) *Command

func (*Command) Flags

func (cmd *Command) Flags() []cli.Flag

func (*Command) Kernel

func (cmd *Command) Kernel() *cli.Command

func (*Command) OnAfterAction

func (cmd *Command) OnAfterAction(action Action) *Command

func (*Command) OnBeforeAction

func (cmd *Command) OnBeforeAction(action Action) *Command

func (*Command) SubCommands

func (cmd *Command) SubCommands() []cli.Command

func (*Command) WithAction

func (cmd *Command) WithAction(action Action) *Command

func (*Command) WithFlagBool

func (cmd *Command) WithFlagBool(name string, value bool, usage string, required bool, hidden ...bool) *Command

func (*Command) WithFlagDuration

func (cmd *Command) WithFlagDuration(name string, value time.Duration, usage string, required bool, hidden ...bool) *Command

func (*Command) WithFlagFloat64

func (cmd *Command) WithFlagFloat64(name string, value float64, usage string, required bool, hidden ...bool) *Command

func (*Command) WithFlagInt

func (cmd *Command) WithFlagInt(name string, value int, usage string, required bool, hidden ...bool) *Command

func (*Command) WithFlagInt64

func (cmd *Command) WithFlagInt64(name string, value int64, usage string, required bool, hidden ...bool) *Command

func (*Command) WithFlagIntSlice

func (cmd *Command) WithFlagIntSlice(name string, value []int, usage string, required bool, hidden ...bool) *Command

WithFlagIntSlice example: main.ext -names Bob -names Tom -names Lisa

func (*Command) WithFlagString

func (cmd *Command) WithFlagString(name string, value string, usage string, required bool, hidden ...bool) *Command

func (*Command) WithFlagStringSlice

func (cmd *Command) WithFlagStringSlice(name string, value []string, usage string, required bool, hidden ...bool) *Command

func (*Command) WithFlagUint

func (cmd *Command) WithFlagUint(name string, value uint, usage string, required bool, hidden ...bool) *Command

func (*Command) WithFlagUint64

func (cmd *Command) WithFlagUint64(name string, value uint64, usage string, required bool, hidden ...bool) *Command

func (*Command) WithUsageErrorHandler

func (cmd *Command) WithUsageErrorHandler(handler UsageErrorHandler) *Command

WithUsageErrorHandler Execute this function if a usage error occurs

type UsageErrorHandler

type UsageErrorHandler = func(v Value, err error, isSubcommand bool) error

type Value

type Value = flag.Value

Jump to

Keyboard shortcuts

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