command

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2023 License: MPL-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Action

type Action = func(*Object) error

type Arg

type Arg struct {
	Index int
	Name  string
	Desc  string
	Value interface{}
}

func (Arg) StringValue

func (c Arg) StringValue() (string, error)

type Args

type Args map[string]*Arg

func (Args) ForIndex

func (c Args) ForIndex(index int) (*Arg, error)

func (Args) HelpString

func (c Args) HelpString() string

func (Args) StringValueForIndex

func (c Args) StringValueForIndex(index int) (string, error)

type Examples

type Examples []string

func (Examples) HelpString

func (c Examples) HelpString(appName, cmdName string) string

type Flag

type Flag struct {
	Name     string
	Desc     string
	Optional bool
	Default  interface{}
	Value    interface{}
}

type Flags

type Flags map[string]*Flag

func (Flags) AllBut

func (c Flags) AllBut(ignore ...string) Flags

func (Flags) BoolValue

func (c Flags) BoolValue(flag string) (bool, error)

func (Flags) DurationValue

func (c Flags) DurationValue(flag string) (time.Duration, error)

func (Flags) GetReflectValue

func (c Flags) GetReflectValue(flag string) (reflect.Value, error)

func (Flags) GetValue

func (c Flags) GetValue(flag string) (interface{}, error)

func (Flags) HelpString

func (c Flags) HelpString() string

func (Flags) Int64Value

func (c Flags) Int64Value(flag string) (int64, error)

func (Flags) IntValue

func (c Flags) IntValue(flag string) (int, error)

func (Flags) RegexValue

func (c Flags) RegexValue(flag string) (*regexp.Regexp, error)

func (Flags) StringSliceValue

func (c Flags) StringSliceValue(flag string) ([]string, error)

func (Flags) StringValue

func (c Flags) StringValue(flag string) (string, error)

func (Flags) TimeValue

func (c Flags) TimeValue(flag string) (time.Time, error)

type Object

type Object struct {
	cli.Command
	App      string
	Name     string
	Desc     string
	Args     Args
	Flags    Flags
	Examples Examples
	Action   Action
	Context  context.Context
}

func New

func New(app, name string, opts ...Option) (*Object, error)

func (*Object) Help

func (c *Object) Help() string

func (*Object) Run

func (c *Object) Run(args []string) int

func (*Object) Synopsis

func (c *Object) Synopsis() string

type Option

type Option = func(*Object) error

func WithAction

func WithAction(action Action) Option

func WithArg

func WithArg(index int, name, desc string) Option

func WithContext

func WithContext(ctx context.Context) Option

func WithDescription

func WithDescription(desc string) Option

func WithExample

func WithExample(example string) Option

func WithFlag

func WithFlag(name, desc string, dflt interface{}) Option

Jump to

Keyboard shortcuts

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