Documentation
¶
Index ¶
- Variables
- func NewCommand(config ...Config) *command
- type CommandWizard
- func (w *CommandWizard) AddChoice(id, question string, options []Option, required ...bool) *CommandWizard
- func (w *CommandWizard) AddConditionalProcess(id, initialMessage string, ...) *CommandWizard
- func (w *CommandWizard) AddConditionalStep(step WizardStep, condition func(results WizardResults) bool) *CommandWizard
- func (w *CommandWizard) AddConfirm(id, question string, defaultValue ...bool) *CommandWizard
- func (w *CommandWizard) AddInfo(id, message string) *CommandWizard
- func (w *CommandWizard) AddMultiChoice(id, question string, options []Option, required ...bool) *CommandWizard
- func (w *CommandWizard) AddProcess(id, initialMessage string, ...) *CommandWizard
- func (w *CommandWizard) AddPrompt(id, question string, required ...bool) *CommandWizard
- func (w *CommandWizard) AddPromptWithDefault(id, question string, defaultValue string) *CommandWizard
- func (w *CommandWizard) AddStep(step WizardStep) *CommandWizard
- func (c CommandWizard) Choice(question string, options []Option, required ...bool) (*Output[Option], error)
- func (c CommandWizard) Confirm(question string) (*Output[bool], error)
- func (c CommandWizard) ConfirmWithDefault(question string, defaultValue bool) (*Output[bool], error)
- func (w *CommandWizard) GetBoolResult(id string) (bool, bool)
- func (w *CommandWizard) GetMultiOptionResult(id string) ([]Option, bool)
- func (w *CommandWizard) GetOptionResult(id string) (Option, bool)
- func (w *CommandWizard) GetResult(id string) (any, bool)
- func (w *CommandWizard) GetStringResult(id string) (string, bool)
- func (c CommandWizard) MultiChoice(question string, options []Option, required ...bool) (*Output[[]Option], error)
- func (w *CommandWizard) PrintSummary()
- func (c CommandWizard) Prompt(question string, required ...bool) (*Output[string], error)
- func (c CommandWizard) PromptWithDefault(question string, defaultValue string) (*Output[string], error)
- func (w *CommandWizard) Run() (WizardResults, error)
- type Config
- type Option
- type Output
- type ResultColor
- type StepType
- type WizardConfig
- type WizardResults
- type WizardStep
Constants ¶
This section is empty.
Variables ¶
var ( // System. ErrReaderFailedRead = errors.New("command reader failed to read") ErrMakeTermRaw = errors.New("failed to create raw terminal") // Prompt. ErrCancelled = errors.New("cancelled by user") ErrInterrupted = errors.New("interrupted by user") ErrResponseRequired = errors.New("response is required") )
Functions ¶
Types ¶
type CommandWizard ¶
type CommandWizard struct {
// contains filtered or unexported fields
}
CommandWizard extends command with wizard functionality.
func NewCommandWizard ¶
func NewCommandWizard(config ...any) *CommandWizard
NewCommandWizard creates a new command wizard instance.
func (*CommandWizard) AddChoice ¶
func (w *CommandWizard) AddChoice(id, question string, options []Option, required ...bool) *CommandWizard
AddChoice adds a choice step.
func (*CommandWizard) AddConditionalProcess ¶
func (w *CommandWizard) AddConditionalProcess( id, initialMessage string, processFn func(results WizardResults, progress func(string)) (any, error), condition func(WizardResults) bool, ) *CommandWizard
AddConditionalProcess adds a conditional processing step.
func (*CommandWizard) AddConditionalStep ¶
func (w *CommandWizard) AddConditionalStep(step WizardStep, condition func(results WizardResults) bool) *CommandWizard
AddConditionalStep adds a step with condition.
func (*CommandWizard) AddConfirm ¶
func (w *CommandWizard) AddConfirm(id, question string, defaultValue ...bool) *CommandWizard
AddConfirm adds a confirm step.
func (*CommandWizard) AddInfo ¶
func (w *CommandWizard) AddInfo(id, message string) *CommandWizard
AddInfo adds an info step (display only).
func (*CommandWizard) AddMultiChoice ¶
func (w *CommandWizard) AddMultiChoice(id, question string, options []Option, required ...bool) *CommandWizard
AddMultiChoice adds a multi-choice step.
func (*CommandWizard) AddProcess ¶
func (w *CommandWizard) AddProcess( id, initialMessage string, processFn func(results WizardResults, progress func(string)) (any, error), ) *CommandWizard
AddProcess adds a processing step for long-running operations.
func (*CommandWizard) AddPrompt ¶
func (w *CommandWizard) AddPrompt(id, question string, required ...bool) *CommandWizard
AddPrompt adds a prompt step.
func (*CommandWizard) AddPromptWithDefault ¶
func (w *CommandWizard) AddPromptWithDefault(id, question string, defaultValue string) *CommandWizard
AddPromptWithDefault adds a prompt with default value step.
func (*CommandWizard) AddStep ¶
func (w *CommandWizard) AddStep(step WizardStep) *CommandWizard
AddStep adds a step to the wizard.
func (CommandWizard) Choice ¶
func (c CommandWizard) Choice(question string, options []Option, required ...bool) (*Output[Option], error)
Choice displays the single choice prompt and returns the `*Output` otherwise `error`.
func (CommandWizard) ConfirmWithDefault ¶
func (*CommandWizard) GetBoolResult ¶
func (w *CommandWizard) GetBoolResult(id string) (bool, bool)
GetBoolResult gets a boolean result by ID.
func (*CommandWizard) GetMultiOptionResult ¶
func (w *CommandWizard) GetMultiOptionResult(id string) ([]Option, bool)
GetMultiOptionResult gets a []Option result by ID.
func (*CommandWizard) GetOptionResult ¶
func (w *CommandWizard) GetOptionResult(id string) (Option, bool)
GetOptionResult gets an Option result by ID.
func (*CommandWizard) GetResult ¶
func (w *CommandWizard) GetResult(id string) (any, bool)
GetResult gets a specific result by ID.
func (*CommandWizard) GetStringResult ¶
func (w *CommandWizard) GetStringResult(id string) (string, bool)
GetStringResult gets a string result by ID.
func (CommandWizard) MultiChoice ¶
func (c CommandWizard) MultiChoice(question string, options []Option, required ...bool) (*Output[[]Option], error)
MultiChoice displays the multiple choice prompt and returns the `*Output` otherwise `error`.
func (*CommandWizard) PrintSummary ¶
func (w *CommandWizard) PrintSummary()
PrintSummary prints a summary of all wizard results.
func (CommandWizard) PromptWithDefault ¶
func (c CommandWizard) PromptWithDefault(question string, defaultValue string) (*Output[string], error)
PromptWithDefault displays prompt command with default value and return `string`.
func (*CommandWizard) Run ¶
func (w *CommandWizard) Run() (WizardResults, error)
Run executes the wizard.
type Output ¶
type Output[T result] struct {
// contains filtered or unexported fields
}
Output defines command output.
func (*Output[T]) PrintResponse ¶
func (o *Output[T]) PrintResponse()
PrintResponse prints command output.
func (*Output[T]) WithContext ¶
WithContext adds context into the command output.
type ResultColor ¶
type ResultColor uint8
ResultColor defines available colors for result text.
const ( ColorDefault ResultColor = iota // Auto-detect or default. ColorLightGray // Light gray (\033[37m). ColorWhite // White (\033[97m). ColorCyan // Cyan (\033[96m). ColorLightBlue // Light blue (\033[94m). ColorYellow // Yellow (\033[93m). ColorGreen // Green (\033[92m). )
type WizardConfig ¶
type WizardConfig struct {
Title string
Description string
ShowProgress bool
ClearScreen bool
ClearHistory bool // Clear terminal scroll history.
ResultColor ResultColor
ShowFinish bool // Show finish screen.
FinishMessage string // Custom finish message.
}
WizardConfig configuration for wizard.
type WizardResults ¶
WizardResults holds all results from wizard steps.
type WizardStep ¶
type WizardStep struct {
ID string
Type StepType
Question string
Options []Option
Required bool
Default any // For default values.
// Conditional execution.
Condition func(results WizardResults) bool
// Custom validation.
Validate func(value any) error
// Transform/modify result before storing.
Transform func(value any) any
// Process function for long-running operations.
Process func(results WizardResults, progress func(string)) (any, error)
}
WizardStep defines a single step in the wizard.