commander

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2022 License: Apache-2.0 Imports: 5 Imported by: 2

Documentation

Index

Constants

View Source
const (
	StringFlag = iota
	IntFlag
	Int64Flag
	Float64Flag
	BoolFlag
)

Supported flags.

Variables

This section is empty.

Functions

func AddFlag

func AddFlag(cmd *Command, config FlagConfig)

AddFlag attaches a flag of the given type with the specified configuration.

Types

type Cols

type Cols []string

Cols contains the header for the column based CLI displayer.

func NewCols

func NewCols(vals ...string) Cols

NewCols returns a cols type.

func NoCols

func NoCols() Cols

NoCols is a 0 column indicator.

type Command

type Command struct {
	*cobra.Command
	// contains filtered or unexported fields
}

Command wraps a base cobra command to add some custom functionality.

func Builder

func Builder(parent *Command, config Config, cols Cols) *Command

Builder constructs a new command.

func (*Command) AddCommand

func (c *Command) AddCommand(commands ...*Command)

AddCommand adds child commands and also to cobra.

func (*Command) GetSubCommands

func (c *Command) GetSubCommands() []*Command

GetSubCommands returns the command sub commands.

type Config

type Config struct {
	DisableAutoGenTag     bool
	DisableSuggentions    bool
	Hidden                bool
	SuggestMinDistance    int
	LongDesc              string
	Deprecated            string
	Example               string
	Namespace             string
	ShortDesc             string
	Version               string
	Aliases               []string
	SuggestFor            []string
	ValidArgs             []string
	Execute               func(cmd *cobra.Command, args []string)
	PersistentPostHook    func(cmd *cobra.Command, args []string)
	PersistentPreHook     func(cmd *cobra.Command, args []string)
	PostHook              func(cmd *cobra.Command, args []string)
	PreHook               func(cmd *cobra.Command, args []string)
	ExecuteErr            func(cmd *cobra.Command, args []string) error
	PersistentPostHookErr func(cmd *cobra.Command, args []string) error
	PersistentPreHookErr  func(cmd *cobra.Command, args []string) error
	PostHookErr           func(cmd *cobra.Command, args []string) error
	PreHookErr            func(cmd *cobra.Command, args []string) error
	ValidArgsFunc         func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective)
}

Config contains a command configuration.

type FlagBindOptions

type FlagBindOptions struct {
	Bound       bool
	BindInt     *int
	BindInt64   *int64
	BindString  *string
	BindBool    *bool
	BindFloat64 *float64
}

FlagBindOptions exposes the parameters used to bind a flag to a passed pointer.

type FlagConfig

type FlagConfig struct {
	FlagType   int
	Name       string
	Shorthand  string
	Usage      string
	Default    interface{}
	Required   bool
	Persistent bool
	Binding    FlagBindOptions
}

FlagConfig defines the configuration of a flag.

Jump to

Keyboard shortcuts

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