internal

package
v0.4.1 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	UnknownStr  = "Unknown"
	ArgumentStr = "Argument"
	OptionStr   = "Option"
	CommandStr  = "Command"
	ParentStr   = "Parent"
)
View Source
const (
	TagMsg    = "msg"
	TagOpt    = "opt"
	TagRename = "rename"
)

Tags is a list of tags used in this package.

View Source
const DiffFromValueKind = 200
View Source
const NumberKinds = 4

Argument, Option, Command, Parent

Variables

View Source
var OptLogger = log.New(os.Stderr, "[OPT] ", log.LstdFlags|log.Llongfile)

Functions

func IsPointer

func IsPointer(a any) bool

func MatchAndSetField

func MatchAndSetField(structPtr any, tree *Tree, args *[]string) (nextStruct any, err error)

func OptFatal

func OptFatal(v ...any)

func RunAfter

func RunAfter(i any) error

func RunBefore

func RunBefore(i any) error

func RunRun

func RunRun(i any) error

func SetValueInStruct

func SetValueInStruct[T any](vStruct reflect.Value, key string, value T) bool

func ToAny

func ToAny(i any) any

Types

type Afterer

type Afterer interface {
	After() error
}

type Beforer

type Beforer interface {
	Before() error
}

type BuilderOptions

type BuilderOptions struct {
	Author  string
	Version string
	About   string
}

func (BuilderOptions) String

func (b BuilderOptions) String() string

type FieldInfo

type FieldInfo struct {
	Field     *refl.StructField
	Index     int
	Name      string
	Kind      FieldKind
	KindIndex int
	InnerType refl.Type
	Message   string
	Opt       FieldOpt
	Usage     string
}

FieldInfo holds information about a field in a opter struct.

func (*FieldInfo) InnerGet

func (f *FieldInfo) InnerGet() any

func (*FieldInfo) IsInnerTypeHelp

func (f *FieldInfo) IsInnerTypeHelp() bool

func (*FieldInfo) Validate

func (f *FieldInfo) Validate() (err error)

type FieldKind

type FieldKind int
const (
	UnknownKind FieldKind = iota + DiffFromValueKind
	ArgumentKind
	OptionKind
	CommandKind
	ParentKind
)

Field kind

func FieldKindFromString

func FieldKindFromString(s string) FieldKind

func (FieldKind) KindIndexKey

func (f FieldKind) KindIndexKey() int

func (FieldKind) String

func (f FieldKind) String() string

type FieldOpt

type FieldOpt struct {
	// contains filtered or unexported fields
}

FieldOpt is an information of FieldInfo struct.

func ParseTagOpt

func ParseTagOpt(tagOpt string) (options FieldOpt)

func (FieldOpt) Required

func (o FieldOpt) Required() bool

func (FieldOpt) String

func (o FieldOpt) String() string

type Getter

type Getter[T constraints.InputType] interface {
	Get() T
}

type Input

type Input[T constraints.InputType] struct {
	// contains filtered or unexported fields
}

func (*Input[T]) Get

func (i *Input[T]) Get() T

func (*Input[T]) GetUsage

func (i *Input[T]) GetUsage() string

func (*Input[T]) Set

func (i *Input[T]) Set(value T)

func (*Input[T]) SetUsage

func (i *Input[T]) SetUsage(usage string)

func (*Input[T]) Unset

func (i *Input[T]) Unset()

func (*Input[T]) Validate

func (i *Input[T]) Validate(validator func(T) error) error

func (*Input[T]) ValueKind

func (i *Input[T]) ValueKind() refl.Kind

type Runner

type Runner interface {
	Run() error
}

type Setter

type Setter[T constraints.InputType] interface {
	Set(value T)
}

type Stringify

type Stringify struct {
	strings.Builder
}

func (*Stringify) WriteStrings

func (sb *Stringify) WriteStrings(s ...string) (int, error)

type Tree

type Tree struct {
	Arguments []*FieldInfo
	Options   map[string]*FieldInfo
	Commands  map[string]*FieldInfo
	Required  map[*FieldInfo]bool
	// contains filtered or unexported fields
}

Tree is for parsing and matching arguments. It also helps to generate help message.

func MakeTree

func MakeTree(structPtr any, parent any, options BuilderOptions) (tree *Tree, err error)

func NewTree

func NewTree(options BuilderOptions) *Tree

func Parse

func Parse(structPtr any, args []string, options BuilderOptions) (tree *Tree, err error)

func (*Tree) Add

func (tree *Tree) Add(info *FieldInfo)

func (*Tree) BuilderOptions

func (tree *Tree) BuilderOptions() BuilderOptions

func (*Tree) Footer

func (tree *Tree) Footer() string

func (*Tree) ToHelp

func (tree *Tree) ToHelp() string

func (*Tree) Total

func (tree *Tree) Total() int

type UnsafeSetter

type UnsafeSetter interface {
	UnsafeSet(value any)
}

type Unsetter

type Unsetter interface {
	Unset()
}

type Validater

type Validater[T constraints.InputType] interface {
	Validate(validator func(T) error) error
	GetUsage() string
	SetUsage(usage string)
}

type ValueKindGetter

type ValueKindGetter interface {
	ValueKind() refl.Kind
}

Jump to

Keyboard shortcuts

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