Documentation
¶
Overview ¶
Package params defines the typed parameter spec for spin.toml. It maps the user-facing prompt types onto huh.Field at form-build time and onto a uniform Value at render time.
Index ¶
- Constants
- func Form(ps []Param, values map[string]any) *huh.Form
- func FuncMap() template.FuncMap
- func Run(ps []Param, values map[string]any) error
- func SetDefaults(ps []Param, values map[string]any)
- func ShellQuote(s string) string
- func SnakeCase(s string) string
- func ValidateDefaults(ps []Param) error
- type BoolParam
- func (p *BoolParam) Apply(v Value)
- func (p *BoolParam) Default() any
- func (p *BoolParam) HuhField(values map[string]any) huh.Field
- func (p *BoolParam) Name() string
- func (p *BoolParam) Prompt() string
- func (p *BoolParam) SetDefault(values map[string]any)
- func (p *BoolParam) String() string
- func (p *BoolParam) Type() Type
- func (p *BoolParam) Value() Value
- type ErrUnknownType
- type MultiSelectParam
- func (p *MultiSelectParam) Apply(v Value)
- func (p *MultiSelectParam) Default() any
- func (p *MultiSelectParam) HuhField(values map[string]any) huh.Field
- func (p *MultiSelectParam) Name() string
- func (p *MultiSelectParam) Prompt() string
- func (p *MultiSelectParam) SetDefault(values map[string]any)
- func (p *MultiSelectParam) String() string
- func (p *MultiSelectParam) Type() Type
- func (p *MultiSelectParam) Value() Value
- type NumberParam
- func (p *NumberParam) Apply(v Value)
- func (p *NumberParam) Default() any
- func (p *NumberParam) HuhField(values map[string]any) huh.Field
- func (p *NumberParam) Name() string
- func (p *NumberParam) Prompt() string
- func (p *NumberParam) SetDefault(values map[string]any)
- func (p *NumberParam) String() string
- func (p *NumberParam) Type() Type
- func (p *NumberParam) Value() Value
- type Param
- type PathParam
- func (p *PathParam) Apply(v Value)
- func (p *PathParam) Default() any
- func (p *PathParam) HuhField(values map[string]any) huh.Field
- func (p *PathParam) Name() string
- func (p *PathParam) Prompt() string
- func (p *PathParam) SetDefault(values map[string]any)
- func (p *PathParam) String() string
- func (p *PathParam) Type() Type
- func (p *PathParam) Value() Value
- type SecretParam
- func (p *SecretParam) Apply(v Value)
- func (p *SecretParam) Default() any
- func (p *SecretParam) HuhField(values map[string]any) huh.Field
- func (p *SecretParam) Name() string
- func (p *SecretParam) Prompt() string
- func (p *SecretParam) SetDefault(values map[string]any)
- func (p *SecretParam) String() string
- func (p *SecretParam) Type() Type
- func (p *SecretParam) Value() Value
- type SelectParam
- func (p *SelectParam) Apply(v Value)
- func (p *SelectParam) Default() any
- func (p *SelectParam) HuhField(values map[string]any) huh.Field
- func (p *SelectParam) Name() string
- func (p *SelectParam) Prompt() string
- func (p *SelectParam) SetDefault(values map[string]any)
- func (p *SelectParam) String() string
- func (p *SelectParam) Type() Type
- func (p *SelectParam) Value() Value
- type Spec
- type SpecMap
- type TextParam
- func (p *TextParam) Apply(v Value)
- func (p *TextParam) Default() any
- func (p *TextParam) HuhField(values map[string]any) huh.Field
- func (p *TextParam) Name() string
- func (p *TextParam) Prompt() string
- func (p *TextParam) SetDefault(values map[string]any)
- func (p *TextParam) String() string
- func (p *TextParam) Type() Type
- func (p *TextParam) Value() Value
- type TextareaParam
- func (p *TextareaParam) Apply(v Value)
- func (p *TextareaParam) Default() any
- func (p *TextareaParam) HuhField(values map[string]any) huh.Field
- func (p *TextareaParam) Name() string
- func (p *TextareaParam) Prompt() string
- func (p *TextareaParam) SetDefault(values map[string]any)
- func (p *TextareaParam) String() string
- func (p *TextareaParam) Type() Type
- func (p *TextareaParam) Value() Value
- type Type
- type Value
Constants ¶
const PageSize = 4
PageSize is the number of params grouped per "page" in the huh form. huh renders each Group as a separate page (user navigates with Next/Prev), so this cap is also the visible pagination granularity. 4 keeps the page scannable on a 24-line terminal.
Variables ¶
This section is empty.
Functions ¶
func Form ¶
Form builds a huh.Form from a slice of params. Params are grouped PageSize-at-a-time into huh.Groups; each Group becomes one form page the user can step through with Next/Prev. A single page is rendered when len(ps) <= PageSize.
func FuncMap ¶
FuncMap returns the set of template functions available to both file rendering (template.Render) and prompt/default rendering (renderStr). A template author can therefore use the same helpers (snake_case, kebab, quote, ...) in a param's prompt or default as they would in a .tmpl file. This is the single source of truth for those helpers; template/engine.go delegates to it.
func Run ¶
Run executes the form on the given params. The form populates each param's value in place. values are the currently known template values, used to render prompts/defaults.
func SetDefaults ¶
SetDefaults applies each param's default value to its current value. Useful when running non-interactively. values are used to render any templated defaults.
func ShellQuote ¶
ShellQuote wraps s in single quotes, escaping any embedded single quotes with the standard "'='"'"' trick.
func ValidateDefaults ¶
ValidateDefaults checks resolved param values for consistency in the non-interactive path, where huh's per-field Validate does not run. It enforces that a select param's value is one of its options: a templated default (e.g. `default = "{{ .ed }}"`) or a --param value that resolves outside the option list would otherwise pass through silently and produce a broken scaffold.
Types ¶
type BoolParam ¶
type BoolParam struct {
// contains filtered or unexported fields
}
func (*BoolParam) SetDefault ¶
type ErrUnknownType ¶
ErrUnknownType is returned when a param declares a type we don't recognise.
func (ErrUnknownType) Error ¶
func (e ErrUnknownType) Error() string
type MultiSelectParam ¶
type MultiSelectParam struct {
// contains filtered or unexported fields
}
func NewMultiSelect ¶
func NewMultiSelect(name, prompt string, options, def []string) *MultiSelectParam
func (*MultiSelectParam) Apply ¶
func (p *MultiSelectParam) Apply(v Value)
func (*MultiSelectParam) Default ¶
func (p *MultiSelectParam) Default() any
func (*MultiSelectParam) HuhField ¶
func (p *MultiSelectParam) HuhField(values map[string]any) huh.Field
func (*MultiSelectParam) Name ¶
func (p *MultiSelectParam) Name() string
func (*MultiSelectParam) Prompt ¶
func (p *MultiSelectParam) Prompt() string
func (*MultiSelectParam) SetDefault ¶
func (p *MultiSelectParam) SetDefault(values map[string]any)
func (*MultiSelectParam) String ¶
func (p *MultiSelectParam) String() string
func (*MultiSelectParam) Type ¶
func (p *MultiSelectParam) Type() Type
func (*MultiSelectParam) Value ¶
func (p *MultiSelectParam) Value() Value
type NumberParam ¶
type NumberParam struct {
// contains filtered or unexported fields
}
NumberParam has no dedicated huh type; we use NewInput + a Validate that parses the input as int and applies Min/Max bounds. The string backing field (valueStr) is what huh writes into via Value(&p.valueStr); the numeric value is derived on demand from Value() and from SetDefaults.
func (*NumberParam) Apply ¶
func (p *NumberParam) Apply(v Value)
func (*NumberParam) Default ¶
func (p *NumberParam) Default() any
func (*NumberParam) Name ¶
func (p *NumberParam) Name() string
func (*NumberParam) Prompt ¶
func (p *NumberParam) Prompt() string
func (*NumberParam) SetDefault ¶
func (p *NumberParam) SetDefault(values map[string]any)
func (*NumberParam) String ¶
func (p *NumberParam) String() string
func (*NumberParam) Type ¶
func (p *NumberParam) Type() Type
func (*NumberParam) Value ¶
func (p *NumberParam) Value() Value
type Param ¶
type Param interface {
Name() string
Type() Type
Prompt() string
Default() any
SetDefault(values map[string]any)
Apply(v Value)
Value() Value
// HuhField builds the huh field for this param. The form runner
// writes the result back via Apply(). values are the currently
// known template values, used to render the param's prompt and
// default (e.g. `prompt = "Name for {{ .name }}"`).
HuhField(values map[string]any) huh.Field
// String returns a one-line summary, used by `spin new --print-params`.
String() string
}
Param is the interface implemented by every typed parameter.
type PathParam ¶
type PathParam struct {
// contains filtered or unexported fields
}
PathParam is a huh.NewFilePicker; default is used as the placeholder starting directory (or filename if non-existent).
func (*PathParam) SetDefault ¶
type SecretParam ¶
type SecretParam struct {
// contains filtered or unexported fields
}
SecretParam is a huh.Input with EchoModePassword.
func NewSecret ¶
func NewSecret(name, prompt string) *SecretParam
func (*SecretParam) Apply ¶
func (p *SecretParam) Apply(v Value)
func (*SecretParam) Default ¶
func (p *SecretParam) Default() any
func (*SecretParam) Name ¶
func (p *SecretParam) Name() string
func (*SecretParam) Prompt ¶
func (p *SecretParam) Prompt() string
func (*SecretParam) SetDefault ¶
func (p *SecretParam) SetDefault(values map[string]any)
func (*SecretParam) String ¶
func (p *SecretParam) String() string
func (*SecretParam) Type ¶
func (p *SecretParam) Type() Type
func (*SecretParam) Value ¶
func (p *SecretParam) Value() Value
type SelectParam ¶
type SelectParam struct {
// contains filtered or unexported fields
}
func (*SelectParam) Apply ¶
func (p *SelectParam) Apply(v Value)
func (*SelectParam) Default ¶
func (p *SelectParam) Default() any
func (*SelectParam) Name ¶
func (p *SelectParam) Name() string
func (*SelectParam) Prompt ¶
func (p *SelectParam) Prompt() string
func (*SelectParam) SetDefault ¶
func (p *SelectParam) SetDefault(values map[string]any)
func (*SelectParam) String ¶
func (p *SelectParam) String() string
func (*SelectParam) Type ¶
func (p *SelectParam) Type() Type
func (*SelectParam) Value ¶
func (p *SelectParam) Value() Value
type Spec ¶
type Spec struct {
Type Type `toml:"type"`
Prompt string `toml:"prompt"`
Default any `toml:"default"`
Min *int `toml:"min"`
Max *int `toml:"max"`
Options []string `toml:"options"`
}
Spec is the raw shape we accept from a parsed spin.toml block. The parse step turns a Spec into a concrete Param.
type TextParam ¶
type TextParam struct {
// contains filtered or unexported fields
}
func (*TextParam) SetDefault ¶
type TextareaParam ¶
type TextareaParam struct {
// contains filtered or unexported fields
}
func NewTextarea ¶
func NewTextarea(name, prompt, def string) *TextareaParam
func (*TextareaParam) Apply ¶
func (p *TextareaParam) Apply(v Value)
func (*TextareaParam) Default ¶
func (p *TextareaParam) Default() any
func (*TextareaParam) Name ¶
func (p *TextareaParam) Name() string
func (*TextareaParam) Prompt ¶
func (p *TextareaParam) Prompt() string
func (*TextareaParam) SetDefault ¶
func (p *TextareaParam) SetDefault(values map[string]any)
func (*TextareaParam) String ¶
func (p *TextareaParam) String() string
func (*TextareaParam) Type ¶
func (p *TextareaParam) Type() Type
func (*TextareaParam) Value ¶
func (p *TextareaParam) Value() Value
type Value ¶
Value is the resolved value of a Param after the form has run. Only one of the data fields is populated, depending on Kind.
func FromAny ¶
FromAny converts a raw CLI/default value (string, int, bool, []string, []any) into a params.Value suitable for Param.Apply. The Value's Kind is derived from the Go type; each param's Apply picks the field it cares about, so a string maps cleanly onto text, select, textarea, secret and path params.