sflag

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jan 26, 2023 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CapNoLimit = -1
)

Variables

This section is empty.

Functions

func UsageFunc

func UsageFunc(groups ...*Group) func() string

Types

type Flag

type Flag struct {
	Name  string
	Usage string
	Value Value
	// contains filtered or unexported fields
}

type FlagOption

type FlagOption func(*Flag)

func WithDenyDuplicate

func WithDenyDuplicate() FlagOption

type FlagRef added in v0.3.0

type FlagRef[T any] struct {
	Value func() T
	Flag  func() *Flag
}

type FlagSet

type FlagSet struct {
	Usage func() string
	// contains filtered or unexported fields
}

func NewFlagSet

func NewFlagSet(name string) *FlagSet

func (*FlagSet) Args

func (f *FlagSet) Args() []string

func (*FlagSet) Bool

func (f *FlagSet) Bool(name, usage string) FlagRef[bool]

Bool presents `-flag“ NOT `-flag true/false`

func (*FlagSet) FixedStringFlags added in v0.3.0

func (f *FlagSet) FixedStringFlags(name, usage string) FlagRef[[][2]string]

FixedStringFlags presents `-flag <value1> <value2> -flag <value3> <value4> -flag ...` This is a reference implementation

func (*FlagSet) Lookup

func (f *FlagSet) Lookup(name string) *Flag

func (*FlagSet) NewGroup

func (f *FlagSet) NewGroup(name string) *Group

func (*FlagSet) Parse

func (f *FlagSet) Parse(args []string) error

func (*FlagSet) String

func (f *FlagSet) String(name, usage string) FlagRef[string]

String presents `-flag <value>`

func (*FlagSet) StringFlags added in v0.3.0

func (f *FlagSet) StringFlags(name, usage string) FlagRef[[]string]

StringFlags presents `-flag <value1> -flag <value2> -flag <value3> -flag ...`

func (*FlagSet) Strings added in v0.3.0

func (f *FlagSet) Strings(name, usage string) FlagRef[[]string]

Strings presents `-flag <value1> <value2> <value3> ...`

func (*FlagSet) Var

func (f *FlagSet) Var(v Value, name, usage string, opts ...FlagOption) *Flag

type FlagType added in v0.2.0

type FlagType int
const (
	TypeRequired FlagType = iota + 1
	TypeOptional
)

func (FlagType) String added in v0.2.0

func (t FlagType) String() string

type Group

type Group struct {
	Name string
	// contains filtered or unexported fields
}

func LookupGroup

func LookupGroup(groups ...*Group) (*Group, error)

func (*Group) AddDescription

func (g *Group) AddDescription(s string) *Group

func (*Group) AddOptional added in v0.3.0

func (g *Group) AddOptional(flag *Flag) *Group

func (*Group) AddRequired added in v0.3.0

func (g *Group) AddRequired(flag *Flag) *Group

func (*Group) Lookup

func (g *Group) Lookup(name string) *Flag

func (*Group) LookupByType

func (g *Group) LookupByType(typ FlagType) []*Flag

func (*Group) NonGroupFlagNames added in v0.3.0

func (g *Group) NonGroupFlagNames() []string

NonGroupFlagNames returns non group flag with specified

func (*Group) Seen

func (g *Group) Seen(name string) bool

func (*Group) Usage

func (g *Group) Usage() string

type Value

type Value interface {
	Set(string) error
	Get() any
}

func Bool

func Bool(p *bool) Value

func FixedStringFlags added in v0.3.0

func FixedStringFlags(p *[][2]string) Value

func FlagValue

func FlagValue[T any](p *T, from func(v string) (T, error)) Value

func String

func String(p *string) Value

func StringFlags added in v0.3.0

func StringFlags(p *[]string) Value

func Strings added in v0.3.0

func Strings(p *[]string) Value

type Values

type Values interface {
	Value
	Cap() int
}

func FlagValues

func FlagValues[T any](p *T, from func(v string) (T, error), cap func() int) Values

Jump to

Keyboard shortcuts

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