Documentation ¶
Index ¶
Constants ¶
const ( // HelpTextTag is the name of the struct tags 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 *flag.FlagSet ParseFunc func() error // NameCfg defines tunables for constructing flag-names NameCfg *NameConfig // contains filtered or unexported fields }
Set is a flagset
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 = flag.Must(flag.NewCmdLineSet(flag.DefaultFlagNameConfig(), config))
func NewCmdLineSet ¶
func NewCmdLineSet(cfg *NameConfig, template interface{}) (*Set, error)
NewCmdLineSet registers flags for the passed template value in the standard library's main flag.CommandLine FlagSet so binaries using dials for flag configuration can play nicely with libraries that register flags with the standard library. (or libraries using dials can register flags and let the actual process's Main() call Parse())
func NewSetWithArgs ¶
func NewSetWithArgs(cfg *NameConfig, template interface{}, args []string) (*Set, error)
NewSetWithArgs creates a new FlagSet and registers flags in it
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 `dialsflag` 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.