input

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package input provides interactive user input functionality for the terminal.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithInput

func WithInput(ctx context.Context, i *Input) context.Context

WithInput returns a new context with the Input attached.

Types

type ConfirmOptions

type ConfirmOptions struct {
	Prompt        string
	Default       bool
	SkipCondition bool
}

ConfirmOptions configures the behavior of Confirm prompts.

func NewConfirmOptions

func NewConfirmOptions() *ConfirmOptions

NewConfirmOptions creates default ConfirmOptions.

func (*ConfirmOptions) WithDefault

func (o *ConfirmOptions) WithDefault(def bool) *ConfirmOptions

WithDefault sets the default value.

func (*ConfirmOptions) WithPrompt

func (o *ConfirmOptions) WithPrompt(prompt string) *ConfirmOptions

WithPrompt sets the prompt message.

func (*ConfirmOptions) WithSkipCondition

func (o *ConfirmOptions) WithSkipCondition(skip bool) *ConfirmOptions

WithSkipCondition sets whether to skip the prompt.

type Input

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

func FromContext

func FromContext(ctx context.Context) *Input

FromContext retrieves the Input from the context. Returns nil if no Input is present.

func MustFromContext

func MustFromContext(ctx context.Context) *Input

MustFromContext retrieves the Input from the context. Panics if no Input is present.

func New

func New(ioStreams *terminal.IOStreams, cliParams *settings.Run) *Input

func (*Input) Confirm

func (i *Input) Confirm(opts *ConfirmOptions) (bool, error)

func (*Input) ReadLine

func (i *Input) ReadLine(opts *LineOptions) (string, error)

func (*Input) ReadPassword

func (i *Input) ReadPassword(opts *PasswordOptions) (string, error)

type LineOptions

type LineOptions struct {
	Prompt     string
	Default    string
	AllowEmpty bool
	Validator  func(string) error
}

LineOptions configures the behavior of ReadLine prompts.

func NewLineOptions

func NewLineOptions() *LineOptions

NewLineOptions creates default LineOptions.

func (*LineOptions) WithAllowEmpty

func (o *LineOptions) WithAllowEmpty(allow bool) *LineOptions

WithAllowEmpty sets whether empty input is allowed.

func (*LineOptions) WithDefault

func (o *LineOptions) WithDefault(def string) *LineOptions

WithDefault sets the default value.

func (*LineOptions) WithPrompt

func (o *LineOptions) WithPrompt(prompt string) *LineOptions

WithPrompt sets the prompt message.

func (*LineOptions) WithValidator

func (o *LineOptions) WithValidator(validator func(string) error) *LineOptions

WithValidator sets a validation function.

type PasswordOptions

type PasswordOptions struct {
	Prompt              string
	ConfirmPrompt       string
	RequireConfirmation bool
	MinLength           int
	AllowEmpty          bool
}

PasswordOptions configures the behavior of ReadPassword prompts.

func NewPasswordOptions

func NewPasswordOptions() *PasswordOptions

NewPasswordOptions creates default PasswordOptions.

func (*PasswordOptions) WithAllowEmpty

func (o *PasswordOptions) WithAllowEmpty(allow bool) *PasswordOptions

WithAllowEmpty sets whether empty passwords are allowed.

func (*PasswordOptions) WithConfirmPrompt

func (o *PasswordOptions) WithConfirmPrompt(prompt string) *PasswordOptions

WithConfirmPrompt sets the confirmation prompt message.

func (*PasswordOptions) WithConfirmation

func (o *PasswordOptions) WithConfirmation(require bool) *PasswordOptions

WithConfirmation enables/disables password confirmation.

func (*PasswordOptions) WithMinLength

func (o *PasswordOptions) WithMinLength(length int) *PasswordOptions

WithMinLength sets the minimum password length.

func (*PasswordOptions) WithPrompt

func (o *PasswordOptions) WithPrompt(prompt string) *PasswordOptions

WithPrompt sets the password prompt message.

Jump to

Keyboard shortcuts

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