Documentation
¶
Index ¶
- func FlagToEnvUppercase(prefix string, s string) string
- func InstallOptionsWatchDog(dog func(cc *Options))
- func IsZeroValue(f *flag.Flag, value string) bool
- func OptionsOptionDeclareWithDefault() interface{}
- func ParseArgs(obj interface{}, args []string, opts ...Option) ([]string, error)
- func ParseArgsToMapStringString(args []string) map[string]string
- func PrintDefaults(f *flag.FlagSet, suffixLines ...string)
- func UnquoteUsage(ff *flag.Flag) (name string, usage string)
- type FlagInfo
- type FlagList
- type KeyFormat
- type LogFunc
- type Maker
- func (fm *Maker) EnvKeysMapping(prefix string, validKeys []string) map[string]string
- func (fm *Maker) FlagKeys() []string
- func (fm *Maker) FlagSet() *flag.FlagSet
- func (fm *Maker) Parse(args []string) error
- func (fm *Maker) ParseArgs(obj interface{}, args []string) ([]string, error)
- func (fm *Maker) PrintDefaults()
- func (fm *Maker) Set(obj interface{}) error
- type Option
- func WithFlagCreateIgnoreFiledPath(v ...string) Option
- func WithFlagSet(v *flag.FlagSet) Option
- func WithFlagValueProvider(v vars.FlagValueProvider) Option
- func WithFlatten(v bool) Option
- func WithKeyFormat(v KeyFormat) Option
- func WithLogDebug(v LogFunc) Option
- func WithLogWarning(v LogFunc) Option
- func WithName(v string) Option
- func WithStringAlias(v func(s string) string) Option
- func WithTagName(v string) Option
- func WithUsageTagName(v string) Option
- type Options
- func (cc *Options) ApplyOption(opts ...Option) []Option
- func (cc *Options) GetFlagCreateIgnoreFiledPath() []string
- func (cc *Options) GetFlagSet() *flag.FlagSet
- func (cc *Options) GetFlagValueProvider() vars.FlagValueProvider
- func (cc *Options) GetFlatten() bool
- func (cc *Options) GetKeyFormat() KeyFormat
- func (cc *Options) GetLogDebug() LogFunc
- func (cc *Options) GetLogWarning() LogFunc
- func (cc *Options) GetName() string
- func (cc *Options) GetStringAlias() func(s string) string
- func (cc *Options) GetTagName() string
- func (cc *Options) GetUsageTagName() string
- type OptionsInterface
- type OptionsVisitor
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FlagToEnvUppercase ¶ added in v0.2.1
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
IsZeroValue check is zero val
func OptionsOptionDeclareWithDefault ¶
func OptionsOptionDeclareWithDefault() interface{}
OptionsOptionDeclareWithDefault go-lint
func ParseArgsToMapStringString ¶
ParseArgsToMapStringString 简单的将arg按照flag的格式解析到map
func PrintDefaults ¶
PrintDefaults 打印FlagSet,替换默认实现
Types ¶
type FlagList ¶
type FlagList struct {
List []*FlagInfo
}
FlagList FlagInfo list
func GetFlagInfo ¶
GetFlagInfo get FlagList from given FlagSet
func (*FlagList) FlagGetAndDel ¶ added in v0.2.1
FlagGetAndDel return FlagInfo by name and del it
type Maker ¶
type Maker struct {
// contains filtered or unexported fields
}
Maker xflag通过Maker自动创建flag
func (*Maker) EnvKeysMapping ¶
EnvKeysMapping 返回内部FlagSet的所有key的env形式(大写,.替换为_)到key的映射关系
type Option ¶
Option option func
func WithFlagCreateIgnoreFiledPath ¶ added in v0.2.5
WithFlagCreateIgnoreFiledPath option func for filed FlagCreateIgnoreFiledPath
func WithFlagSet ¶
WithFlagSet option func for filed FlagSet
func WithFlagValueProvider ¶
func WithFlagValueProvider(v vars.FlagValueProvider) Option
WithFlagValueProvider option func for filed FlagValueProvider
func WithKeyFormat ¶
WithKeyFormat option func for filed KeyFormat
func WithLogWarning ¶
WithLogWarning option func for filed LogWarning
func WithStringAlias ¶ added in v0.2.6
WithStringAlias option func for filed StringAlias
func WithUsageTagName ¶
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 (*Options) ApplyOption ¶
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 (*Options) GetFlagSet ¶
func (*Options) GetFlagValueProvider ¶
func (cc *Options) GetFlagValueProvider() vars.FlagValueProvider
func (*Options) GetFlatten ¶
func (*Options) GetKeyFormat ¶
func (*Options) GetLogDebug ¶
func (*Options) GetLogWarning ¶
func (*Options) GetStringAlias ¶ added in v0.2.6
func (*Options) GetTagName ¶
func (*Options) GetUsageTagName ¶
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