Documentation
¶
Overview ¶
Package forms implements interactive terminal forms that collect user input and produce structured data. Forms are defined as YAML documents containing typed properties (string, bool, integer, float, password, object, array) that are presented to the user interactively. Properties support conditionals, validation expressions, enums, defaults, and nested sub-properties.
The collected answers are assembled into a map[string]any result using an internal entry tree (see graph.go) that supports querying partially-built results, enabling conditional properties that reference earlier answers.
Index ¶
- Constants
- func ProcessBytes(f []byte, env map[string]any, opts ...processOption) (map[string]any, error)
- func ProcessFile(f string, env map[string]any, opts ...processOption) (map[string]any, error)
- func ProcessForm(f Form, env map[string]any, opts ...processOption) (map[string]any, error)
- func ProcessReader(r io.Reader, env map[string]any, opts ...processOption) (map[string]any, error)
- type Form
- type Property
Constants ¶
const ( ArrayIfEmpty = "array" // emit an empty array ObjectIfEmpty = "object" // emit an empty object AbsentIfEmpty = "absent" // omit the key entirely )
IfEmpty constants control what value is emitted when a property answer is empty.
const ( StringType = "string" BoolType = "bool" IntType = "integer" FloatType = "float" PasswordType = "password" ObjectType = "object" ArrayType = "array" )
Type constants identify property types in form definitions.
Variables ¶
This section is empty.
Functions ¶
func ProcessBytes ¶
ProcessBytes unmarshals f as a YAML form definition and processes it interactively.
func ProcessFile ¶
ProcessFile reads YAML form data from the file at path f and processes it interactively.
func ProcessForm ¶
ProcessForm presents the form interactively on a terminal and returns the collected answers as a map. It requires a valid terminal (stdin and stdout). The env map provides template variables for property descriptions and conditional expressions.
Types ¶
type Form ¶
type Form struct {
Name string `json:"name" yaml:"name"`
Description string `json:"description" yaml:"description"`
Properties []Property `json:"properties" yaml:"properties"`
}
Form defines an interactive form with a name, description, and a list of properties to present to the user. The Description supports Go template syntax with Sprig functions and color markup tags like {red}text{/red}.
type Property ¶
type Property struct {
Name string `json:"name" yaml:"name"`
Description string `json:"description" yaml:"description"`
Help string `json:"help" yaml:"help"`
IfEmpty string `json:"empty" yaml:"empty"`
Type string `json:"type" yaml:"type"`
ConditionalExpression string `json:"conditional" yaml:"conditional"`
ValidationExpression string `json:"validation" yaml:"validation"`
Required bool `json:"required" yaml:"required"`
Default string `json:"default" yaml:"default"`
Enum []string `json:"enum" yaml:"enum"`
Properties []Property `json:"properties" yaml:"properties"`
}
Property defines a single form field. Type determines the input method (string, bool, integer, float, password, object, array). Properties with sub-Properties create nested structures. ConditionalExpression is a validation expression evaluated against the current environment and collected input to decide whether to present this property.