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 NestedType
- type PFlagProvider
- type PFlagProviderGenerator
- type SliceOrArray
- type Tag
- 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 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
Adds any needed imports for types not directly declared in this package.
func (PFlagProvider) WriteCodeFile ¶
func (p PFlagProvider) WriteCodeFile(outputFilePath string) error
Evaluates the main code file template and writes the output to outputFilePath
func (PFlagProvider) WriteTestFile ¶
func (p PFlagProvider) WriteTestFile(outputFilePath string) error
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 SliceOrArray ¶
type 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 TestStrategy ¶
type TestStrategy string
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"` }