xflag

package
v0.3.26 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2024 License: Unlicense Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FlagToEnvUppercase added in v0.2.1

func FlagToEnvUppercase(prefix string, s string) string

FlagToEnvUppercase flag字符串转换到env

func InstallOptionsWatchDog

func InstallOptionsWatchDog(dog func(cc *Options))

InstallOptionsWatchDog the installed func will called when NewOptions called

func IsZeroValue added in v0.2.8

func IsZeroValue(f *flag.Flag, value string) bool

IsZeroValue check is zero val

func OptionsOptionDeclareWithDefault

func OptionsOptionDeclareWithDefault() interface{}

OptionsOptionDeclareWithDefault go-lint

func ParseArgs

func ParseArgs(obj interface{}, args []string, opts ...Option) ([]string, error)

ParseArgs 根据option创建Maker并解析Args

func ParseArgsToMapStringString

func ParseArgsToMapStringString(args []string) map[string]string

ParseArgsToMapStringString 简单的将arg按照flag的格式解析到map

func PrintDefaults

func PrintDefaults(f *flag.FlagSet, suffixLines ...string)

PrintDefaults 打印FlagSet,替换默认实现

func UnquoteUsage added in v0.2.4

func UnquoteUsage(ff *flag.Flag) (name string, usage string)

UnquoteUsage linke flag.UnquoteUsage

Types

type FlagInfo

type FlagInfo struct {
	Name     string
	TypeName string
	Usage    string
	DefValue string
	Flag     *flag.Flag
}

FlagInfo flag basic info

type FlagList

type FlagList struct {
	List []*FlagInfo
}

FlagList FlagInfo list

func GetFlagInfo

func GetFlagInfo(f *flag.FlagSet) (ret FlagList)

GetFlagInfo get FlagList from given FlagSet

func (*FlagList) Flag

func (f *FlagList) Flag(name string) *FlagInfo

Flag return FlagInfo by name

func (*FlagList) FlagGetAndDel added in v0.2.1

func (f *FlagList) FlagGetAndDel(name string) *FlagInfo

FlagGetAndDel return FlagInfo by name and del it

type KeyFormat

type KeyFormat func(string) string

KeyFormat key格式,当指定的tag无val时调用改方法格式化

type LogFunc

type LogFunc func(string)

LogFunc 日志方法

type Maker

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

Maker xflag通过Maker自动创建flag

func NewMaker

func NewMaker(opts ...Option) *Maker

NewMaker 根据option创建Maker

func (*Maker) EnvKeysMapping

func (fm *Maker) EnvKeysMapping(prefix string, validKeys []string) map[string]string

EnvKeysMapping 返回内部FlagSet的所有key的env形式(大写,.替换为_)到key的映射关系

func (*Maker) FlagKeys

func (fm *Maker) FlagKeys() []string

FlagKeys 返回内部FlagSet的所有key

func (*Maker) FlagSet

func (fm *Maker) FlagSet() *flag.FlagSet

FlagSet 返回指定的FlagSet

func (*Maker) Parse

func (fm *Maker) Parse(args []string) error

Parse 解析给定的tag并绑定到FlagSet的Flag中

func (*Maker) ParseArgs

func (fm *Maker) ParseArgs(obj interface{}, args []string) ([]string, error)

ParseArgs parses the arguments based on the FlagMaker's setting.

func (*Maker) PrintDefaults

func (fm *Maker) PrintDefaults()

PrintDefaults 通FlagSet的PrintDefaults

func (*Maker) Set

func (fm *Maker) Set(obj interface{}) error

Set 将obj绑定到FlagSet中,将自动创建到Falg的定义中

type Option

type Option func(cc *Options) Option

Option option func

func WithFlagCreateIgnoreFiledPath added in v0.2.5

func WithFlagCreateIgnoreFiledPath(v ...string) Option

WithFlagCreateIgnoreFiledPath option func for filed FlagCreateIgnoreFiledPath

func WithFlagSet

func WithFlagSet(v *flag.FlagSet) Option

WithFlagSet option func for filed FlagSet

func WithFlagValueProvider

func WithFlagValueProvider(v vars.FlagValueProvider) Option

WithFlagValueProvider option func for filed FlagValueProvider

func WithFlatten

func WithFlatten(v bool) Option

WithFlatten option func for filed Flatten

func WithKeyFormat

func WithKeyFormat(v KeyFormat) Option

WithKeyFormat option func for filed KeyFormat

func WithLogDebug

func WithLogDebug(v LogFunc) Option

WithLogDebug option func for filed LogDebug

func WithLogWarning

func WithLogWarning(v LogFunc) Option

WithLogWarning option func for filed LogWarning

func WithName

func WithName(v string) Option

WithName option func for filed Name

func WithStringAlias added in v0.2.6

func WithStringAlias(v func(s string) string) Option

WithStringAlias option func for filed StringAlias

func WithTagName

func WithTagName(v string) Option

WithTagName option func for filed TagName

func WithUsageTagName

func WithUsageTagName(v string) Option

WithUsageTagName option func for filed UsageTagName

type Options

type Options struct {
	Name                      string
	TagName                   string // 使用的tag key,如不设定则使用
	UsageTagName              string
	Flatten                   bool // 是否使用扁平模式,不使用.分割
	FlagSet                   *flag.FlagSet
	FlagValueProvider         vars.FlagValueProvider
	KeyFormat                 KeyFormat
	FlagCreateIgnoreFiledPath []string
	LogDebug                  LogFunc
	LogWarning                LogFunc
	StringAlias               func(s string) string
}

Options should use NewOptions to initialize it

func NewOptions

func NewOptions(opts ...Option) *Options

NewOptions new Options

func (*Options) ApplyOption

func (cc *Options) ApplyOption(opts ...Option) []Option

ApplyOption apply multiple new option and return the old ones sample: old := cc.ApplyOption(WithTimeout(time.Second)) defer cc.ApplyOption(old...)

func (*Options) GetFlagCreateIgnoreFiledPath added in v0.2.5

func (cc *Options) GetFlagCreateIgnoreFiledPath() []string

func (*Options) GetFlagSet

func (cc *Options) GetFlagSet() *flag.FlagSet

func (*Options) GetFlagValueProvider

func (cc *Options) GetFlagValueProvider() vars.FlagValueProvider

func (*Options) GetFlatten

func (cc *Options) GetFlatten() bool

func (*Options) GetKeyFormat

func (cc *Options) GetKeyFormat() KeyFormat

func (*Options) GetLogDebug

func (cc *Options) GetLogDebug() LogFunc

func (*Options) GetLogWarning

func (cc *Options) GetLogWarning() LogFunc

func (*Options) GetName

func (cc *Options) GetName() string

all getter func

func (*Options) GetStringAlias added in v0.2.6

func (cc *Options) GetStringAlias() func(s string) string

func (*Options) GetTagName

func (cc *Options) GetTagName() string

func (*Options) GetUsageTagName

func (cc *Options) GetUsageTagName() string

type OptionsInterface

type OptionsInterface interface {
	OptionsVisitor
	ApplyOption(...Option) []Option
}

OptionsInterface visitor + ApplyOption interface for Options

type OptionsVisitor

type OptionsVisitor interface {
	GetName() string
	GetTagName() string
	GetUsageTagName() string
	GetFlatten() bool
	GetFlagSet() *flag.FlagSet
	GetFlagValueProvider() vars.FlagValueProvider
	GetKeyFormat() KeyFormat
	GetFlagCreateIgnoreFiledPath() []string
	GetLogDebug() LogFunc
	GetLogWarning() LogFunc
	GetStringAlias() func(s string) string
}

OptionsVisitor visitor interface for Options

Directories

Path Synopsis
templates

Jump to

Keyboard shortcuts

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