clapper

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TagName = "clapper"
)

Variables

View Source
var (
	ErrNoStruct                        = errors.New("target is not a struct")
	ErrEmptyArgument                   = errors.New("empty argument")
	ErrUnexpectedValue                 = errors.New("expected flag not value")
	ErrFieldCanNotBeSet                = errors.New("field can't be set")
	ErrNoFlagSpecifier                 = errors.New("no flag specified for struct field")
	ErrRequiredValueNotGiven           = errors.New("required value not given and no default value provided")
	ErrShortOverrideCanOnlyBeOneLetter = errors.New("short override can only be one letter")
	ErrLongMustBeMoreThanOne           = errors.New("long name must be more than one character")
)

Functions

func DefaultHelpFormatter

func DefaultHelpFormatter(item *HelpItem, formatting *HelpFormatting) string

func Help

func Help[T any](target *T, formatter FormatterFn) (string, error)

func HelpDefault

func HelpDefault[T any](target *T) (string, error)

func Parse

func Parse[T any](target *T, rawArgs ...string) (trailing []string, err error)

func StringReflect

func StringReflect(field reflect.StructField, fieldValue reflect.Value, values []string) (int, error)

func ValueFromString

func ValueFromString(fieldType reflect.Type, inputs []string) (*reflect.Value, int, error)

Types

type ArgsParser

type ArgsParser struct {
	Params   map[string][]string
	Trailing []string
	// contains filtered or unexported fields
}

func NewArgsParser

func NewArgsParser() *ArgsParser

func (*ArgsParser) Add

func (pa *ArgsParser) Add(arg string) error

func (*ArgsParser) Parse

func (pa *ArgsParser) Parse(args []string) (*ArgsParser, error)

func (*ArgsParser) PopTrailing

func (pa *ArgsParser) PopTrailing(took int) *ArgsParser

func (*ArgsParser) ValuesEqualWith

func (pa *ArgsParser) ValuesEqualWith(other *ArgsParser) bool

func (*ArgsParser) With

func (pa *ArgsParser) With(modifier func(args *ArgsParser)) *ArgsParser

type ArgsState

type ArgsState int
const (
	ArgsStart ArgsState = iota
	ArgsShort
	ArgsLong
)

type FormatterFn

type FormatterFn = func(item *HelpItem, formatting *HelpFormatting) string

type HelpFormatting

type HelpFormatting struct {
	InvokationMax int
	DefaultMax    int
}

func DefaultHelpFormatting

func DefaultHelpFormatting() *HelpFormatting

func (*HelpFormatting) Update

func (h *HelpFormatting) Update(item *HelpItem) *HelpFormatting

type HelpItem

type HelpItem struct {
	Invokation string
	Default    *string
	Help       *string
}

func HelpItemFromTags

func HelpItemFromTags(tags map[TagType]Tag) *HelpItem

func (*HelpItem) Display

func (h *HelpItem) Display(formatting HelpFormatting) string

type ParseError

type ParseError struct {
	Index   int
	Name    string
	TagLine string
	// contains filtered or unexported fields
}

func NewParseError

func NewParseError(from error, index int, name string, tagLine string) ParseError

func (ParseError) Error

func (e ParseError) Error() string

func (ParseError) Underlying

func (e ParseError) Underlying() error

type Tag

type Tag struct {
	Type  TagType
	Name  string
	Value string
	Index int
}

func NewTag

func NewTag(tag string, fieldName string, index int) (*Tag, error)

func (*Tag) DeriveName

func (t *Tag) DeriveName(fieldName string) string

func (*Tag) HasValue

func (t *Tag) HasValue() bool

func (*Tag) Validate

func (t *Tag) Validate() error

type TagType

type TagType int
const (
	TagShort TagType = iota
	TagLong
	TagDefault
	TagHelp
)

func GetTagType

func GetTagType(tag string) (TagType, error)

type UnsupportedReflectTypeError

type UnsupportedReflectTypeError struct {
	Type string
}

func NewUnsupportedReflectTypeError

func NewUnsupportedReflectTypeError(t string) UnsupportedReflectTypeError

func (UnsupportedReflectTypeError) Error

Jump to

Keyboard shortcuts

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