initwiz

package
v0.10.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 5, 2026 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package initwiz provides init wizard state management and types for TerraCi. It contains the StateMap for huh form binding and all init-related type definitions (InitContributor, InitGroupSpec, InitField, etc.).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FieldType

type FieldType string

FieldType identifies the kind of form field in the init wizard.

const (
	FieldString FieldType = "string"
	FieldBool   FieldType = "bool"
	FieldSelect FieldType = "select"
)

type InitCategory

type InitCategory string

InitCategory determines how an InitGroupSpec is rendered in the wizard.

const (
	// CategoryProvider groups contain CI-specific infrastructure settings (image, runner).
	CategoryProvider InitCategory = "provider"
	// CategoryPipeline groups contain pipeline behavior settings (plan_enabled, auto_approve).
	CategoryPipeline InitCategory = "pipeline"
	// CategoryFeature groups contain optional feature toggles.
	CategoryFeature InitCategory = "feature"
	// CategoryDetail groups contain detail settings for enabled features.
	CategoryDetail InitCategory = "detail"
)

type InitContribution

type InitContribution struct {
	PluginKey string
	Config    map[string]any
}

InitContribution holds the config produced by a plugin's init logic.

type InitContributor

type InitContributor interface {
	plugin.Plugin
	InitGroups() []*InitGroupSpec
	BuildInitConfig(state *StateMap) *InitContribution
}

InitContributor plugins contribute fields and config to the init wizard.

type InitField

type InitField struct {
	Key         string
	Title       string
	Description string
	Type        FieldType
	Default     any
	Options     []InitOption
	Placeholder string
}

InitField describes a single form field in the init wizard.

type InitGroupSpec

type InitGroupSpec struct {
	Title    string
	Category InitCategory
	Order    int
	Fields   []InitField
	ShowWhen func(*StateMap) bool
}

InitGroupSpec describes a group of form fields contributed by a plugin.

type InitOption

type InitOption struct {
	Label string
	Value string
}

InitOption represents a selectable option for a field.

type StateMap

type StateMap struct {
	// contains filtered or unexported fields
}

StateMap is the typed init state backed by a single map[string]any. It exposes typed accessors for plugins (String/Bool) and stable pointers for huh form field binding (StringPtr/BoolPtr).

Lifecycle:

  1. Core/plugins call Set("key", value) to populate defaults.
  2. Plugins call StringPtr("key") / BoolPtr("key") to obtain stable pointers for huh fields. The first call upgrades the slot from the plain value to a typed pointer; subsequent Set/Get/String/Bool keep working through that pointer.
  3. huh forms mutate values through the pointers during the wizard.
  4. After the form completes, BuildInitConfig reads back via Get/String/Bool.

All accessors flow through the same map, so Set after StringPtr now updates the value backing that pointer (no more silent staleness).

func NewStateMap

func NewStateMap() *StateMap

NewStateMap creates an empty StateMap.

func (*StateMap) Binary

func (s *StateMap) Binary() string

Binary returns the current terraform binary name.

func (*StateMap) Bool

func (s *StateMap) Bool(key string) bool

Bool returns the value at key as a bool, or false if missing or of a non-bool type.

func (*StateMap) BoolPtr

func (s *StateMap) BoolPtr(key string) *bool

BoolPtr returns a stable *bool pointer for huh form binding. If the slot already holds a *bool it is returned unchanged; if it held a plain bool the slot is upgraded to a pointer initialized with that bool.

func (*StateMap) Get

func (s *StateMap) Get(key string) any

Get retrieves a value, transparently dereferencing pointer-backed slots.

func (*StateMap) Provider

func (s *StateMap) Provider() string

Provider returns the current provider name.

func (*StateMap) Set

func (s *StateMap) Set(key string, val any)

Set stores a value, transparently honoring any *string / *bool slot previously installed by StringPtr / BoolPtr so existing form bindings keep observing the new value.

func (*StateMap) String

func (s *StateMap) String(key string) string

String returns the value at key as a string, or "" if missing or of a non-string type.

func (*StateMap) StringPtr

func (s *StateMap) StringPtr(key string) *string

StringPtr returns a stable *string pointer for huh form binding. If the slot already holds a *string it is returned unchanged; if it held a plain string the slot is upgraded to a pointer initialized with that string.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL