Documentation ¶
Index ¶
- Constants
- Variables
- func DefaultRenamer(parent, name string, isAct bool) string
- func PrettyStruct(in any, prefix string) string
- func Register[T any](c RegisteredConverters)
- type Filler
- func (filler *Filler) Fill(in any) error
- func (filler *Filler) GetActUsage(actname string) string
- func (filler *Filler) GetFlagset() *flag.FlagSet
- func (filler *Filler) Parse() ([]string, error)
- func (filler *Filler) ParseArgs(args []string) ([]string, error)
- func (filler *Filler) Usage()
- func (filler *Filler) UsageStr(prefix string) string
- type FillerOption
- type FromStrFunc
- type RegisteredConverters
- type RenameFunc
- type ToStrFunc
Constants ¶
const ( //SkipTag is the struct field tag used to skip flag generation SkipTag = "skipflag" //AliasTag is the struct field tag used to specify the parameter name iso field name AliasTag = "alias" //UsageTag is the struct field tag used to specify the usage of the field UsageTag = "usage" //ActTag is the struct field tag used to specify the field is an action ActTag = "action" )
const ( //default flag.ErrorHandling DefaultErrHandle = flag.ExitOnError )
Variables ¶
var DefaultTimeLayout = "2006-01-02 15:04:05"
DefaultTimeLayout is the default layout string to parse time, following golang time.Parse() format, can be overridden per field by field tag "layout". Default value is "2006-01-02 15:04:05", which is the same as time.DateTime in Go 1.20
var ErrInvalidAction = errors.New("unknown action")
Functions ¶
func DefaultRenamer ¶
DefaultRenamer is the default renaming function, it is parent + "-" + name when isAct is true; otherwise return lower case of name
func PrettyStruct ¶ added in v0.1.1
PrettyStruct returns a pretty formatted string representation of in
func Register ¶
func Register[T any](c RegisteredConverters)
Register a new type with corresponding converters
Types ¶
type Filler ¶
type Filler struct {
// contains filtered or unexported fields
}
Filler auto-generates one or multiple flag.FlagSet based on an input struct
func NewFiller ¶
func NewFiller(fsname, usage string, options ...FillerOption) *Filler
NewFiller creates a new Filler, fsname is the name for flagset, usage is the overall usage introduction. optionally, a list of FillerOptions could be specified.
func (*Filler) GetActUsage ¶ added in v0.2.0
GetActUsage returns filler's child action usage specified by actname, actname should be the field name before renaming; return "" if not found
func (*Filler) GetFlagset ¶ added in v0.3.1
GetFlagset returns the flagset used by the filler
func (*Filler) ParseArgs ¶ added in v0.2.0
ParseArgs parse the args, return parsed actions as a slice of string, each is a parsed action name
type FillerOption ¶
type FillerOption func(filler *Filler)
FillerOption is an option when creating new Filler
func WithFlagErrHandling ¶ added in v0.2.0
func WithFlagErrHandling(h flag.ErrorHandling) FillerOption
WithFlagErrHandling returns a FillerOption thats specifies the flag.ErrorHandling
func WithRenamer ¶
func WithRenamer(r RenameFunc) FillerOption
WithRenamer returns a FillerOption that specifies the rename function
type FromStrFunc ¶
FromStrFunc is a function convert string s into a specific type T, the tag is the struct field tag, as addtional input. see time.go for implementation examples
type RegisteredConverters ¶
type RenameFunc ¶
RenameFunc is the function to rename the flag for a struct field, name is the field name, while parent is the parent struct field name, isAct is true when parent is an action