initwiz

package
v0.9.6 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 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 (cost, policy, summary).
	CategoryFeature InitCategory = "feature"
	// CategoryDetail groups contain detail settings for enabled features (policy settings).
	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 maps. It provides both typed accessors and stable pointers for huh form field binding.

Lifecycle:

  1. Core calls Set("key", "default") to populate initial values.
  2. Plugins call StringPtr("key") / BoolPtr("key") to get stable pointers for huh fields.
  3. huh form mutates values through the pointers during user interaction.
  4. After form completes, BuildInitConfig reads back via Get() / String() / Bool().

Get() resolves with priority: StringPtr store > BoolPtr store > Set store. This ensures pointer-backed values (mutated by forms) take precedence.

func NewStateMap

func NewStateMap() *StateMap

NewStateMap creates a new empty StateMap.

func (*StateMap) Binary

func (s *StateMap) Binary() string

Binary returns the current binary name.

func (*StateMap) Bool

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

Bool returns a bool value for the key, or false if not found.

func (*StateMap) BoolPtr

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

BoolPtr returns a stable *bool pointer for huh form binding. If a value was previously Set for the key, it initializes the pointer with that value.

func (*StateMap) Get

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

Get retrieves a value, preferring pointer-backed values from StringPtr/BoolPtr.

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 in the state.

func (*StateMap) String

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

String returns a string value for the key, or empty string if not found.

func (*StateMap) StringPtr

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

StringPtr returns a stable *string pointer for huh form binding. If a value was previously Set for the key, it initializes the pointer with that value.

Jump to

Keyboard shortcuts

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