Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func StructToArgs ¶
StructToArgs converts a struct into a list of arguments of the form '-field-name=value'. If prefix is not empty, args will take the form '-prefix-field-name=value'. String values are quoted, bool, int and float values are not. Note that not all types supported by StructToArgs may be unpacked by StructToFlags.
A flag:"name" tag may be applied to the struct fields to set a custom field name. If no matching tag is found, structflag will try to use a "json" tag. Otherwise the field name is used as is. Finally, all underscores in the field name are replaced with '-'.
func StructToFlags ¶
StructToFlags registers the fields of a struct with the flag package so they may be set with arguments of the form '-field-name=value'. If prefix is not empty, args will take
A flag:"name,description,defaultValue" tag may be applied to the struct fields to set a custom field name, description and defaultValue. If no matching tag is found, structflag will try to use a "json" tag for a field name. Otherwise the field name is used as is. Finally, all underscores in the field name are replaced with '-'. Default values are parsed using normal string conversion methods for the value type.
Supported field types: bool, int, int64, uint,uint64, float64, time.Duration, string Calling StructToFlags with a struct containing unsupported fields will panic.
Types ¶
This section is empty.