sflag

package
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Dec 8, 2022 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

func WithGroup

func WithGroup(g *Group, typ FlagType) FlagOption

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(p *bool, name, usage string, opts ...FlagOption)

Bool presents -flag NOT -flag true/false

func (*FlagSet) FixedStrings

func (f *FlagSet) FixedStrings(p *[]string, name, usage string, opts ...FlagOption)

FixedStrings presents `-flag <value1> <value2>` number of values are specified by initialize of a variable e.g. s := []string{make([]string, 2)} This is a reference implementation

func (*FlagSet) FlexStrings

func (f *FlagSet) FlexStrings(p *[]string, name, usage string, opts ...FlagOption)

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

func (*FlagSet) Lookup

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

func (*FlagSet) MultipleFlagFixedStrings

func (f *FlagSet) MultipleFlagFixedStrings(p *[][2]string, name, usage string, opts ...FlagOption)

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

func (*FlagSet) MultipleFlagString

func (f *FlagSet) MultipleFlagString(p *[]string, name, usage string, opts ...FlagOption)

MultipleFlagString presents `-flag <value1> -flag <value2> -flag <value3>`

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(p *string, name, usage string, opts ...FlagOption)

String presents -flag <value>

func (*FlagSet) Var

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

type FlagType added in v0.2.0

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

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) Add

func (g *Group) Add(flag *Flag, typ FlagType)

func (*Group) AddDescription

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

func (*Group) Diff

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

Diff returns non group flag with specified

func (*Group) Lookup

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

func (*Group) LookupByType

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

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 FixedStrings

func FixedStrings(p *[]string) Value

func FlagValue

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

func FlagValues

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

func FlexStrings

func FlexStrings(p *[]string) Value

func MultipleFlagFixedStrings

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

func MultipleFlagString

func MultipleFlagString(p *[]string) Value

func String

func String(p *string) Value

type Values

type Values interface {
	Value
	Cap() int
}

Jump to

Keyboard shortcuts

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