cli

package
v0.0.0-...-9fce2f1 Latest Latest
Warning

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

Go to latest
Published: May 2, 2022 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrAssertion = errors.New("assertion error")

Functions

func Get

func Get[T OptionType](c Ctx, key string) T

Types

type BoolOption

type BoolOption struct {
	Name     string
	Usage    string
	Required bool
	Value    bool
}

func (BoolOption) Help

func (o BoolOption) Help() string

func (BoolOption) Invalid

func (o BoolOption) Invalid() bool

func (BoolOption) Key

func (o BoolOption) Key() string

func (BoolOption) Var

func (o BoolOption) Var() interface{}

type Cmd

type Cmd struct {
	Name    string
	Help    string
	Version string
	Args    []string
	Options []Option
	Cmds    []*Cmd
	Action  func(Ctx) error

	Intercept Intercept
	// contains filtered or unexported fields
}

func (*Cmd) Init

func (c *Cmd) Init()

func (*Cmd) Register

func (c *Cmd) Register(cmd *Cmd)

func (*Cmd) Run

func (c *Cmd) Run() error

func (*Cmd) RunCtx

func (c *Cmd) RunCtx(ctx context.Context) error

type Ctx

type Ctx interface {
	context.Context
	Args() []string
	Option(string) Option
	Bool(string) bool
	Int(string) int
	Uint(string) uint
	Float(string) float64
	String(string) string
	StringSlice(string) []string
	IntSlice(string) []int
	UintSlice(string) []uint
	FloatSlice(string) []float64
	StringMap(string) map[string]string
	Map(string) map[string]interface{}
}

type FloatOption

type FloatOption struct {
	Name     string
	Usage    string
	Required bool
	Value    float64
}

func (FloatOption) Help

func (o FloatOption) Help() string

func (FloatOption) Invalid

func (o FloatOption) Invalid() bool

func (FloatOption) Key

func (o FloatOption) Key() string

func (FloatOption) Var

func (o FloatOption) Var() interface{}

type FloatSlice

type FloatSlice []float64

func (*FloatSlice) Set

func (s *FloatSlice) Set(value string) error

func (*FloatSlice) String

func (s *FloatSlice) String() string

type FloatSliceOption

type FloatSliceOption struct {
	Name     string
	Usage    string
	Required bool
	Value    []float64
}

func (FloatSliceOption) Help

func (o FloatSliceOption) Help() string

func (FloatSliceOption) Invalid

func (o FloatSliceOption) Invalid() bool

func (FloatSliceOption) Key

func (o FloatSliceOption) Key() string

func (FloatSliceOption) Var

func (o FloatSliceOption) Var() interface{}

type IntOption

type IntOption struct {
	Name     string
	Usage    string
	Required bool
	Value    int
}

func (IntOption) Help

func (o IntOption) Help() string

func (IntOption) Invalid

func (o IntOption) Invalid() bool

func (IntOption) Key

func (o IntOption) Key() string

func (IntOption) Var

func (o IntOption) Var() interface{}

type IntSlice

type IntSlice []int

func (*IntSlice) Set

func (s *IntSlice) Set(value string) error

func (*IntSlice) String

func (s *IntSlice) String() string

type IntSliceOption

type IntSliceOption struct {
	Name     string
	Usage    string
	Required bool
	Value    []int
}

func (IntSliceOption) Help

func (o IntSliceOption) Help() string

func (IntSliceOption) Invalid

func (o IntSliceOption) Invalid() bool

func (IntSliceOption) Key

func (o IntSliceOption) Key() string

func (IntSliceOption) Var

func (o IntSliceOption) Var() interface{}

type Intercept

type Intercept func(Ctx) error

type Map

type Map map[string]interface{}

func (*Map) Set

func (s *Map) Set(value string) error

func (*Map) String

func (s *Map) String() string

type MapOption

type MapOption struct {
	Name     string
	Usage    string
	Required bool
	Value    map[string]interface{}
}

func (MapOption) Help

func (o MapOption) Help() string

func (MapOption) Invalid

func (o MapOption) Invalid() bool

func (MapOption) Key

func (o MapOption) Key() string

func (MapOption) Var

func (o MapOption) Var() interface{}

type Option

type Option interface {
	Key() string
	Help() string
	Invalid() bool
}

type OptionType

type OptionType interface {
	bool | int | uint | float64 | string | []string | []int | []uint | []float64 | map[string]string | map[string]interface{}
}

type StringMap

type StringMap map[string]string

func (*StringMap) Set

func (s *StringMap) Set(value string) error

func (*StringMap) String

func (s *StringMap) String() string

type StringMapOption

type StringMapOption struct {
	Name     string
	Usage    string
	Required bool
	Value    map[string]string
}

func (StringMapOption) Help

func (o StringMapOption) Help() string

func (StringMapOption) Invalid

func (o StringMapOption) Invalid() bool

func (StringMapOption) Key

func (o StringMapOption) Key() string

func (StringMapOption) Var

func (o StringMapOption) Var() interface{}

type StringOption

type StringOption struct {
	Name     string
	Usage    string
	Required bool
	Value    string
}

func (StringOption) Help

func (o StringOption) Help() string

func (StringOption) Invalid

func (o StringOption) Invalid() bool

func (StringOption) Key

func (o StringOption) Key() string

func (StringOption) Var

func (o StringOption) Var() interface{}

type StringSlice

type StringSlice []string

func (*StringSlice) Set

func (s *StringSlice) Set(value string) error

func (*StringSlice) String

func (s *StringSlice) String() string

type StringSliceOption

type StringSliceOption struct {
	Name     string
	Usage    string
	Required bool
	Value    []string
}

func (StringSliceOption) Help

func (o StringSliceOption) Help() string

func (StringSliceOption) Invalid

func (o StringSliceOption) Invalid() bool

func (StringSliceOption) Key

func (o StringSliceOption) Key() string

func (StringSliceOption) Var

func (o StringSliceOption) Var() interface{}

type UintOption

type UintOption struct {
	Name     string
	Usage    string
	Required bool
	Value    uint
}

func (UintOption) Help

func (o UintOption) Help() string

func (UintOption) Invalid

func (o UintOption) Invalid() bool

func (UintOption) Key

func (o UintOption) Key() string

func (UintOption) Var

func (o UintOption) Var() interface{}

type UintSlice

type UintSlice []uint

func (*UintSlice) Set

func (s *UintSlice) Set(value string) error

func (*UintSlice) String

func (s *UintSlice) String() string

type UintSliceOption

type UintSliceOption struct {
	Name     string
	Usage    string
	Required bool
	Value    []uint
}

func (UintSliceOption) Help

func (o UintSliceOption) Help() string

func (UintSliceOption) Invalid

func (o UintSliceOption) Invalid() bool

func (UintSliceOption) Key

func (o UintSliceOption) Key() string

func (UintSliceOption) Var

func (o UintSliceOption) Var() interface{}

type Value

type Value interface {
	Var() interface{}
}

Jump to

Keyboard shortcuts

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