Documentation ¶
Index ¶
- Variables
- func DataTypeNames() []string
- func InputModeNames() []string
- func PromptConfigNames() []string
- func RegisterTransformer(t Transformer)
- func Transform(key string, value any, rule string) (any, error)
- func UnregisterTransformer(t Transformer)
- type DataMap
- type DataType
- func (x DataType) Description() string
- func (x DataType) Enum() []any
- func (x DataType) EnumComments() []string
- func (x DataType) IsValid() bool
- func (x DataType) MarshalText() ([]byte, error)
- func (x DataType) PrepareJSONSchema(schema *jsonschema.Schema) error
- func (x DataType) String() string
- func (x *DataType) UnmarshalText(text []byte) error
- type InputMode
- func (x InputMode) Description() string
- func (x InputMode) Enum() []any
- func (x InputMode) EnumComments() []string
- func (x InputMode) IsValid() bool
- func (x InputMode) MarshalText() ([]byte, error)
- func (x InputMode) PrepareJSONSchema(schema *jsonschema.Schema) error
- func (x InputMode) String() string
- func (x *InputMode) UnmarshalText(text []byte) error
- type PromptConfig
- func (x PromptConfig) Description() string
- func (x PromptConfig) Enum() []any
- func (x PromptConfig) EnumComments() []string
- func (x PromptConfig) IsValid() bool
- func (x PromptConfig) MarshalText() ([]byte, error)
- func (x PromptConfig) PrepareJSONSchema(schema *jsonschema.Schema) error
- func (x PromptConfig) String() string
- func (x *PromptConfig) UnmarshalText(text []byte) error
- type Transformer
- type TransformerFunc
- type Value
- func (v *Value) DisplayName() string
- func (v *Value) FlagName() string
- func (v *Value) Get() any
- func (v *Value) IsArg() bool
- func (v *Value) IsBoolFlag() bool
- func (v *Value) IsEmpty() bool
- func (v *Value) IsEnabled() bool
- func (v *Value) IsFlag() bool
- func (v *Value) IsHidden() bool
- func (v *Value) IsUnset() bool
- func (Value) PrepareJSONSchema(schema *jsonschema.Schema) error
- func (v *Value) Prompt(prompter ui.Prompter) error
- func (v *Value) Set(data string) error
- func (v *Value) ShouldPrompt() bool
- func (v *Value) String() string
- func (v *Value) Type() string
- func (v *Value) Validate() error
- func (v *Value) ValueSet() *ValueSet
- func (v *Value) WithValueCache(dm DataMap) *Value
- func (v *Value) WithValueSet(vs *ValueSet) *Value
- type ValueSet
- func (vs *ValueSet) Add(value *Value) *ValueSet
- func (vs *ValueSet) All() []*Value
- func (vs *ValueSet) Args() []*Value
- func (vs *ValueSet) Cache() DataMap
- func (vs *ValueSet) Flags() []*Value
- func (vs *ValueSet) Get(key string) any
- func (vs *ValueSet) GetAll() map[string]any
- func (vs *ValueSet) Len() int
- func (vs *ValueSet) Partition() ([]*Value, []*Value)
- func (vs *ValueSet) Prepend(value *Value) *ValueSet
- func (vs *ValueSet) Prompt(prompter ui.Prompter) error
- func (vs *ValueSet) Set(key string, value any) error
- func (vs *ValueSet) SetArgs(args []string) ([]string, error)
- func (vs *ValueSet) SetCache(dataMap DataMap) *ValueSet
- func (vs *ValueSet) Validate() error
- func (vs *ValueSet) Value(key string) *Value
Constants ¶
This section is empty.
Variables ¶
var ErrInvalidDataType = fmt.Errorf("not a valid DataType, try [%s]", strings.Join(_DataTypeNames, ", "))
var ErrInvalidInputMode = fmt.Errorf("not a valid InputMode, try [%s]", strings.Join(_InputModeNames, ", "))
var ErrInvalidPromptConfig = fmt.Errorf("not a valid PromptConfig, try [%s]", strings.Join(_PromptConfigNames, ", "))
var (
ErrUnknownTransformer = errors.New("undefined transform")
)
Functions ¶
func DataTypeNames ¶
func DataTypeNames() []string
DataTypeNames returns a list of possible string values of DataType.
func InputModeNames ¶
func InputModeNames() []string
InputModeNames returns a list of possible string values of InputMode.
func PromptConfigNames ¶
func PromptConfigNames() []string
PromptConfigNames returns a list of possible string values of PromptConfig.
func RegisterTransformer ¶
func RegisterTransformer(t Transformer)
func UnregisterTransformer ¶ added in v0.5.1
func UnregisterTransformer(t Transformer)
Types ¶
type DataMap ¶
DataMap is a shared data structure that each value uses when rendering. This allows for values to reference other values (via template expressions) in their defaults.
type DataType ¶
type DataType string
Specifies the data type of a value.
ENUM( bool // Boolean. int // Integer. intSlice // Integer array/slice. string // String. stringSlice // String array/slice. ).
const ( // DataTypeBool is a DataType of type bool. // Boolean. DataTypeBool DataType = "bool" // DataTypeInt is a DataType of type int. // Integer. DataTypeInt DataType = "int" // DataTypeIntSlice is a DataType of type intSlice. // Integer array/slice. DataTypeIntSlice DataType = "intSlice" // DataTypeString is a DataType of type string. // String. DataTypeString DataType = "string" // DataTypeStringSlice is a DataType of type stringSlice. // String array/slice. DataTypeStringSlice DataType = "stringSlice" )
func ParseDataType ¶
ParseDataType attempts to convert a string to a DataType.
func (DataType) Description ¶ added in v0.5.1
Enum implements the jsonschema.Described interface.
func (DataType) EnumComments ¶ added in v0.5.1
EnumComments returns the comment associated with each enum.
func (DataType) IsValid ¶
IsValid provides a quick way to determine if the typed value is part of the allowed enumerated values
func (DataType) MarshalText ¶
MarshalText implements the text marshaller method.
func (DataType) PrepareJSONSchema ¶ added in v0.4.0
PrepareJSONSchema implements the jsonschema.Preparer interface.
func (*DataType) UnmarshalText ¶
UnmarshalText implements the text unmarshaller method.
type InputMode ¶
type InputMode string
Determines how the value can be set.
ENUM( arg // Can be set via positional argument OR prompt. flag // Can be set via flag OR prompt. hidden // Can only be set via user config. ).
const ( // InputModeArg is a InputMode of type arg. // Can be set via positional argument OR prompt. InputModeArg InputMode = "arg" // InputModeFlag is a InputMode of type flag. // Can be set via flag OR prompt. InputModeFlag InputMode = "flag" // InputModeHidden is a InputMode of type hidden. // Can only be set via user config. InputModeHidden InputMode = "hidden" )
func ParseInputMode ¶
ParseInputMode attempts to convert a string to a InputMode.
func (InputMode) Description ¶ added in v0.5.1
Enum implements the jsonschema.Described interface.
func (InputMode) EnumComments ¶ added in v0.5.1
EnumComments returns the comment associated with each enum.
func (InputMode) IsValid ¶
IsValid provides a quick way to determine if the typed value is part of the allowed enumerated values
func (InputMode) MarshalText ¶
MarshalText implements the text marshaller method.
func (InputMode) PrepareJSONSchema ¶ added in v0.4.0
PrepareJSONSchema implements the jsonschema.Preparer interface.
func (*InputMode) UnmarshalText ¶
UnmarshalText implements the text unmarshaller method.
type PromptConfig ¶
type PromptConfig string
Determines when a value should prompt for input.
ENUM( always // Always prompt. never // Never prompt. on-empty // Only when input OR default is blank/zero. on-unset // Only when not explicitly set via CLI. ).
const ( // PromptConfigAlways is a PromptConfig of type always. // Always prompt. PromptConfigAlways PromptConfig = "always" // PromptConfigNever is a PromptConfig of type never. // Never prompt. PromptConfigNever PromptConfig = "never" // PromptConfigOnEmpty is a PromptConfig of type on-empty. // Only when input OR default is blank/zero. PromptConfigOnEmpty PromptConfig = "on-empty" // PromptConfigOnUnset is a PromptConfig of type on-unset. // Only when not explicitly set via CLI. PromptConfigOnUnset PromptConfig = "on-unset" )
func ParsePromptConfig ¶
func ParsePromptConfig(name string) (PromptConfig, error)
ParsePromptConfig attempts to convert a string to a PromptConfig.
func (PromptConfig) Description ¶ added in v0.5.1
func (x PromptConfig) Description() string
Enum implements the jsonschema.Described interface.
func (PromptConfig) Enum ¶ added in v0.4.0
func (x PromptConfig) Enum() []any
Enum implements the jsonschema.Enum interface.
func (PromptConfig) EnumComments ¶ added in v0.5.1
func (x PromptConfig) EnumComments() []string
EnumComments returns the comment associated with each enum.
func (PromptConfig) IsValid ¶
func (x PromptConfig) IsValid() bool
IsValid provides a quick way to determine if the typed value is part of the allowed enumerated values
func (PromptConfig) MarshalText ¶
func (x PromptConfig) MarshalText() ([]byte, error)
MarshalText implements the text marshaller method.
func (PromptConfig) PrepareJSONSchema ¶ added in v0.4.0
func (x PromptConfig) PrepareJSONSchema(schema *jsonschema.Schema) error
PrepareJSONSchema implements the jsonschema.Preparer interface.
func (PromptConfig) String ¶
func (x PromptConfig) String() string
String implements the Stringer interface.
func (*PromptConfig) UnmarshalText ¶
func (x *PromptConfig) UnmarshalText(text []byte) error
UnmarshalText implements the text unmarshaller method.
type Transformer ¶
type Transformer struct { Name string Description string Func TransformerFunc }
func GetTransformer ¶
func GetTransformer(name string) (Transformer, error)
GetTransformer returns the transformer registered for name. If name is not found, returns ErrUnknownTransformer.
func RegisteredTransformers ¶ added in v0.5.1
func RegisteredTransformers() []Transformer
type TransformerFunc ¶ added in v0.5.1
TransformerFunc is a function used to process value data.
func StringTransformerFunc ¶ added in v0.5.1
func StringTransformerFunc(f func(s string) string) TransformerFunc
StringTransformerFunc accepts a string function and returns a TransformerFunc that delegates to it.
type Value ¶
type Value struct { // Note: have to use `DataType` because `Type()` is a pflag.Value method. Key string `mapstructure:"key" validate:"required"` Name string `mapstructure:"name"` Flag string `mapstructure:"flag"` Help string `mapstructure:"help"` DataType DataType `mapstructure:"type" default:"string" validate:"required,oneof=bool int intSlice string stringSlice"` //nolint:lll Default any `mapstructure:"default"` PromptConfig PromptConfig `mapstructure:"prompt" default:"on-unset" validate:"required,oneof=always never on-empty on-unset"` //nolint:lll InputMode InputMode `mapstructure:"mode" default:"flag" validate:"required,oneof=arg flag hidden"` TransformRules string `mapstructure:"transform"` ValidationRules string `mapstructure:"validate"` Options []any `mapstructure:"options" nullable:"false"` If string `mapstructure:"if" default:"true"` // contains filtered or unexported fields }
func (*Value) DisplayName ¶
DisplayName returns the human friendly display name.
func (*Value) Get ¶
Get returns the rendered, casted value. Required to implement flag.Getter interface.
func (*Value) IsBoolFlag ¶
IsBoolFlag returns true if the data type is `bool`. Required to implement [pflag.boolFlag] interface.
func (*Value) IsEnabled ¶ added in v0.3.0
IsEnabled returns true when the `If` field evaluates to true. The user is only prompted for enabled values.
func (Value) PrepareJSONSchema ¶ added in v0.4.1
PrepareJSONSchema implements the jsonschema.Preparer interface.
func (*Value) Set ¶
Set sets the value. Returns an error if the input data can not be casted to the correct type. Required to implement the pflag.Value interface.
func (*Value) ShouldPrompt ¶
ShouldPrompt returns true if the user should be prompted for a value.
func (*Value) String ¶
Required to implement the pflag.Value interface.
func (*Value) WithValueCache ¶
WithValueCache sets dm and returns the receiver. Should only be used in tests.
func (*Value) WithValueSet ¶
WithValueSet sets vs and returns the receiver.
type ValueSet ¶
type ValueSet struct {
// contains filtered or unexported fields
}
ValueSet is a unique set of Values (identified by Value.Key).
func (*ValueSet) Add ¶
Add appends a value to the set. Values are identified by Value.Key and duplicates are overwritten.
func (*ValueSet) Get ¶
Get returns the value data for key. If key is not found, then returns the data for key from the cache.
func (*ValueSet) Prepend ¶ added in v0.3.0
Prepend prepends a value to the set. Values are identified by Value.Key and duplicates are overwritten.
func (*ValueSet) Prompt ¶
Prompt calls Value.Prompt() for each value in the set. Returns the first error received.
func (*ValueSet) Set ¶
Set sets the value data for key. If key is not found, then sets the data in the cache so that it can be used by other values (see SrcPath and DstPath in stamp.Generator).
func (*ValueSet) SetArgs ¶
SetArgs attempts to set all positional values with args. If len(args) > len(ValueSet.Args()), then the remaining items in args are returned.