wizard

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultFlagOrder = 9999

DefaultFlagOrder is the default order value for flags without explicit ordering

Variables

This section is empty.

Functions

func AddWizardFlag

func AddWizardFlag(cmd *cobra.Command)

AddWizardFlag adds the --wizard flag to a command

func ApplyResultToFlags

func ApplyResultToFlags(cmd *cobra.Command, result map[string]any) error

ApplyResultToFlags applies wizard results back to command flags

func EnableWizard

func EnableWizard(cmd *cobra.Command)

EnableWizard adds --wizard flag and wraps PreRunE for a command This is a convenience function that combines AddWizardFlag and WrapPreRunEWithWizard

func EnableWizardForCommands

func EnableWizardForCommands(cmds ...*cobra.Command)

EnableWizardForCommands enables wizard for multiple commands

func RegisterDefaultProvider

func RegisterDefaultProvider(flagName string, fn DefaultProvider)

RegisterDefaultProvider registers a default value provider for a flag name

func RegisterDefaultProviderForCommand

func RegisterDefaultProviderForCommand(cmd *cobra.Command, flagName string, fn DefaultProvider)

RegisterDefaultProviderForCommand registers a default value provider scoped to a command and its children.

func RegisterProvider

func RegisterProvider(flagName string, fn OptionProvider)

RegisterProvider registers a dynamic option provider for a flag name

func RegisterProviderForCommand

func RegisterProviderForCommand(cmd *cobra.Command, flagName string, fn OptionProvider)

RegisterProviderForCommand registers a dynamic option provider scoped to a command and its children.

func RunWizard

func RunWizard(cmd *cobra.Command) (map[string]any, error)

RunWizard runs an interactive wizard for the given command's flags. It returns the collected values as a map, or an error if cancelled.

func WrapPreRunEWithWizard

func WrapPreRunEWithWizard(
	originalPreRunE func(cmd *cobra.Command, args []string) error,
	originalPreRun func(cmd *cobra.Command, args []string),
) func(cmd *cobra.Command, args []string) error

WrapPreRunEWithWizard wraps a command's PreRunE to support wizard mode. Usage: cmd.PreRunE = wizard.WrapPreRunEWithWizard(originalPreRunE, originalPreRun)

func WrapRunEWithWizard

func WrapRunEWithWizard(originalRunE func(cmd *cobra.Command, args []string) error) func(cmd *cobra.Command, args []string) error

WrapRunEWithWizard wraps a command's RunE to support wizard mode Usage: cmd.RunE = wizard.WrapRunEWithWizard(cmd, originalRunE)

Types

type DefaultProvider

type DefaultProvider func() string

DefaultProvider returns a dynamic default value for a flag

type FieldKind

type FieldKind int

FieldKind represents the type of field in the form

const (
	KindSelect FieldKind = iota
	KindMultiSelect
	KindInput
	KindConfirm
	KindNumber
)

type FormField

type FormField struct {
	Name        string
	Title       string
	Description string
	Kind        FieldKind
	Options     []string     // For Select/MultiSelect
	Selected    int          // For Select: current selection index
	MultiSelect map[int]bool // For MultiSelect: selected indices
	InputValue  string       // For Input/Number
	ConfirmVal  bool         // For Confirm
	Required    bool
	Validate    func(string) error
	Value       interface{} // Pointer to store result
}

FormField represents a field that can be displayed in the form

type FormGroup

type FormGroup struct {
	Name        string
	Title       string
	Description string
	Fields      []*FormField
	Optional    bool // If true, this group can be collapsed
	Expanded    bool // If true and Optional, show fields; otherwise collapsed
}

FormGroup represents a group of fields

type FormTheme

type FormTheme struct {
	TabActive          lipgloss.Style
	TabInactive        lipgloss.Style
	TabCompleted       lipgloss.Style
	Separator          lipgloss.Style
	Error              lipgloss.Style
	Help               lipgloss.Style
	FocusedTitle       lipgloss.Style
	NormalTitle        lipgloss.Style
	Description        lipgloss.Style
	SelectedOption     lipgloss.Style
	UnselectedOption   lipgloss.Style
	FocusedUnselected  lipgloss.Style
	MultiSelectChecked lipgloss.Style
	InputFocused       lipgloss.Style
	InputBlurred       lipgloss.Style
	GroupHeader        lipgloss.Style
	GroupHeaderDim     lipgloss.Style
}

FormTheme defines styles for the grouped wizard form

func DefaultFormTheme

func DefaultFormTheme() *FormTheme

DefaultFormTheme returns the default theme for grouped wizard forms

type GroupedWizardForm

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

GroupedWizardForm is a single-page wizard form with all groups visible

func NewGroupedWizardForm

func NewGroupedWizardForm(groups []*FormGroup) *GroupedWizardForm

NewGroupedWizardForm creates a new grouped wizard form

func (*GroupedWizardForm) Aborted

func (f *GroupedWizardForm) Aborted() bool

Aborted returns true if the user cancelled

func (*GroupedWizardForm) Init

func (f *GroupedWizardForm) Init() tea.Cmd

Init implements tea.Model

func (*GroupedWizardForm) Run

func (f *GroupedWizardForm) Run() error

Run executes the grouped form

func (*GroupedWizardForm) Update

func (f *GroupedWizardForm) Update(msg tea.Msg) (tea.Model, tea.Cmd)

Update implements tea.Model

func (*GroupedWizardForm) View

func (f *GroupedWizardForm) View() string

View implements tea.Model - renders all groups on a single page

func (*GroupedWizardForm) WithFormTheme

func (f *GroupedWizardForm) WithFormTheme(theme *FormTheme) *GroupedWizardForm

WithFormTheme sets the form theme for styling

func (*GroupedWizardForm) WithTheme

func (f *GroupedWizardForm) WithTheme(theme *huh.Theme) *GroupedWizardForm

WithTheme sets the huh theme

type OptionProvider

type OptionProvider func() []string

OptionProvider returns dynamic options for a flag's select menu

Jump to

Keyboard shortcuts

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