Documentation ¶
Index ¶
- Constants
- Variables
- func GenerateCodeFile(buffer *bytes.Buffer, info TypeInfo) error
- func GenerateTestFile(buffer *bytes.Buffer, info TypeInfo) error
- type ComplexJSONType
- type FieldInfo
- type NamedType
- type NestedType
- type PFlagProvider
- type PFlagProviderGenerator
- type PFlagValueType
- type SliceOrArray
- type Tag
- type TestConstTypeAlias
- type TestStrategy
- type TestType
- type TypeInfo
Constants ¶
const ( TagName = "pflag" JSONTagName = "json" )
Variables ¶
var DefaultTestType = &TestType{
StringValue: "Welcome to defaults",
}
Functions ¶
Types ¶
type ComplexJSONType ¶
func (*ComplexJSONType) UnmarshalJSON ¶
func (c *ComplexJSONType) UnmarshalJSON(b []byte) error
type NamedType ¶
type NamedType int
func NamedTypeString ¶
NamedTypeString retrieves an enum value from the enum constants string name. Throws an error if the param is not part of the enum.
func NamedTypeValues ¶
func NamedTypeValues() []NamedType
NamedTypeValues returns all values of the enum
func (NamedType) IsANamedType ¶
IsANamedType returns "true" if the value is listed in the enum definition. "false" otherwise
func (NamedType) MarshalJSON ¶
MarshalJSON implements the json.Marshaler interface for NamedType
func (*NamedType) UnmarshalJSON ¶
UnmarshalJSON implements the json.Unmarshaler interface for NamedType
type NestedType ¶
type NestedType struct {
IntValue int `json:"i" pflag:",this is an important flag"`
}
type PFlagProvider ¶
type PFlagProvider struct {
// contains filtered or unexported fields
}
func (PFlagProvider) Imports ¶
func (p PFlagProvider) Imports() map[string]string
Imports adds any needed imports for types not directly declared in this package.
func (PFlagProvider) WriteCodeFile ¶
func (p PFlagProvider) WriteCodeFile(outputFilePath string) error
WriteCodeFile evaluates the main code file template and writes the output to outputFilePath
func (PFlagProvider) WriteTestFile ¶
func (p PFlagProvider) WriteTestFile(outputFilePath string) error
WriteTestFile evaluates the test code file template and writes the output to outputFilePath
type PFlagProviderGenerator ¶
type PFlagProviderGenerator struct {
// contains filtered or unexported fields
}
PFlagProviderGenerator parses and generates GetPFlagSet implementation to add PFlags for a given struct's fields.
func NewGenerator ¶
func NewGenerator(pkg, targetTypeName, defaultVariableName string, shouldBindDefaultVar bool) (*PFlagProviderGenerator, error)
NewGenerator initializes a PFlagProviderGenerator for pflags files for targetTypeName struct under pkg. If pkg is not filled in, it's assumed to be current package (which is expected to be the common use case when invoking pflags from go:generate comments)
func (PFlagProviderGenerator) Generate ¶
func (g PFlagProviderGenerator) Generate(ctx context.Context) (PFlagProvider, error)
func (PFlagProviderGenerator) GetTargetPackage ¶
func (g PFlagProviderGenerator) GetTargetPackage() *types.Package
type PFlagValueType ¶
type SliceOrArray ¶
type Tag ¶
Tag represents parsed PFlag Go-struct tag. type Foo struct { StringValue string `json:"str" pflag:"\"hello world\",This is a string value"` } Name will be "str", Default value is "hello world" and Usage is "This is a string value"
type TestConstTypeAlias ¶
type TestConstTypeAlias = int
type TestStrategy ¶
type TestStrategy string
TestStrategy determines how tests should be generated.
const ( JSON TestStrategy = "Json" SliceJoined TestStrategy = "SliceJoined" Raw TestStrategy = "Raw" )
type TestType ¶
type TestType struct { StringValue string `json:"str" pflag:"\"hello world\",\"life is short\""` BoolValue bool `json:"bl" pflag:"true"` NestedType NestedType `json:"nested"` IntArray []int `json:"ints" pflag:"[]int{12%2C1}"` StringArray []string `json:"strs" pflag:"[]string{\"12\"%2C\"1\"}"` ComplexJSONArray []ComplexJSONType `json:"complexArr"` StringToJSON ComplexJSONType `json:"c" pflag:",I'm a complex type but can be converted from string."` IgnoredMap map[string]string `json:"ignored-map" pflag:"-,"` StorageConfig storage.Config `json:"storage"` IntValue *int `json:"i"` StringMap map[string]string `json:"m" pflag:",I'm a map of strings"` ConstType NamedType `json:"constType"` AliasType TestConstTypeAlias `json:"aliasType"` }