Documentation ¶
Index ¶
- Constants
- type NameConfig
- type Set
- func Must(s *Set, err error) *Set
- func NewCmdLineSet(cfg *NameConfig, template interface{}) (*Set, error)
- func NewDefaultSetWithFlagSet(template interface{}, flagset *pflag.FlagSet) (*Set, error)
- func NewSetWithArgs(cfg *NameConfig, template interface{}, args []string) (*Set, error)
- func NewSetWithFlagSet(cfg *NameConfig, template interface{}, flagset *pflag.FlagSet) (*Set, error)
Constants ¶
const ( // HelpTextTag is the name of the struct tag for flag descriptions HelpTextTag = "dialsdesc" // DefaultFlagHelpText is the default help-text for fields with an // unset dialsdesc tag. DefaultFlagHelpText = "unset description (`" + HelpTextTag + "` struct tag)" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type NameConfig ¶
type NameConfig struct { // FieldNameEncodeCasing is for the field names used by the flatten mangler FieldNameEncodeCasing caseconversion.EncodeCasingFunc // TagEncodeCasing is for the tag names used by the flatten mangler TagEncodeCasing caseconversion.EncodeCasingFunc }
NameConfig defines the parameters for separating components of a flag-name
func DefaultFlagNameConfig ¶
func DefaultFlagNameConfig() *NameConfig
DefaultFlagNameConfig defines a reasonably-defaulted NameConfig for field names and tags
type Set ¶
type Set struct { Flags *pflag.FlagSet ParseFunc func() error // NameCfg defines tunables for constructing flag-names NameCfg *NameConfig // contains filtered or unexported fields }
Set source is provided for compatibility with the cobra command line framework. Others should prefer to use flag.Set
func Must ¶
Must is a helper that wraps a call to a function returning (*Set, error) and panics if the error is non-nil. It is intended for use in variable initializations such as
var flagset = pflag.Must(pflag.NewCmdLineSet(pflag.DefaultFlagNameConfig(), config))
func NewCmdLineSet ¶
func NewCmdLineSet(cfg *NameConfig, template interface{}) (*Set, error)
NewCmdLineSet registers flags for the passed template value in the library's pflag.CommandLine FlagSet so binaries using dials for flag configuration can play nicely with libraries that register flags with the pflag library. (or libraries using dials can register flags and let the actual process's Main() call Parse())
func NewDefaultSetWithFlagSet ¶
NewDefaultSetWithFlagSet uses the passedin pflag FlagSet and registers flags with the DefaultFlagNameConfig
func NewSetWithArgs ¶
func NewSetWithArgs(cfg *NameConfig, template interface{}, args []string) (*Set, error)
NewSetWithArgs creates a new pflag FlagSet and registers flags in it
func NewSetWithFlagSet ¶
func NewSetWithFlagSet(cfg *NameConfig, template interface{}, flagset *pflag.FlagSet) (*Set, error)
NewSetWithFlagSet uses the passed in pflag FlagSet and registers flags
func (*Set) Value ¶
Value fills in the user-provided config struct using flags. It looks up the flags to bind into a given struct field by using that field's `dialspflag` struct tag if present, then its `dials` tag if present, and finally its name. If the struct has nested fields, Value will flatten the fields so flags can be defined for nested fields.