interactive

package
v0.2.0-rc.3 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package interactive provides CLI-level helpers for interactive user prompts.

These helpers wrap the SDK's interactive package with CLI-specific concerns such as --yes flag bypass, --no-input global flag bypass, and consistent error handling across all commands.

Index

Constants

This section is empty.

Variables

View Source
var ErrCancelled = errors.New("operation cancelled by user")

ErrCancelled is returned when the user cancels a confirmation prompt (Ctrl+C).

View Source
var ErrNoOptions = errors.New("no options provided")

ErrNoOptions is returned when Select or MultiSelect is called with an empty options list.

Functions

func Confirm

func Confirm(message string, opts ...ConfirmOption) (bool, error)

Confirm prompts the user for a yes/no confirmation.

The prompt is bypassed (returns true) when:

  • The --yes flag is set via WithYesFlag(true)
  • The --no-input global flag is active

Returns true if confirmed, false if denied, or an error if the prompt fails. Returns ErrCancelled if the user presses Ctrl+C.

func Input

func Input(message string, opts ...InputOption) (string, error)

Input prompts the user for text input.

The prompt is bypassed when the --no-input global flag is active, returning the default value if set, or an empty string otherwise.

Returns the user's input string, or an error if the prompt fails. Returns ErrCancelled if the user presses Ctrl+C.

func MultiSelect

func MultiSelect(message string, options []string, opts ...MultiSelectOption) ([]string, error)

MultiSelect prompts the user to choose multiple options from a list.

The prompt is bypassed when the --no-input global flag is active, returning the defaults if set, or all options otherwise.

Returns the selected options, or an error if the prompt fails. Returns ErrCancelled if the user presses Ctrl+C. Returns ErrNoOptions if the options slice is empty.

func Password

func Password(message string, opts ...PasswordOption) (string, error)

Password prompts the user for a password (input is masked).

The prompt is bypassed when the --no-input global flag is active, returning an empty string. Passwords have no default value for security.

Returns the user's password string, or an error if the prompt fails. Returns ErrCancelled if the user presses Ctrl+C.

func Select

func Select(message string, options []string, opts ...SelectOption) (string, error)

Select prompts the user to choose a single option from a list.

The prompt is bypassed when the --no-input global flag is active, returning the default value if set, or the first option otherwise.

Returns the selected option string, or an error if the prompt fails. Returns ErrCancelled if the user presses Ctrl+C. Returns ErrNoOptions if the options slice is empty.

func SetNoInputGetter

func SetNoInputGetter(getter func() bool)

SetNoInputGetter sets the function used to check if --no-input is active. Called from root.go init() to wire up the global flag.

Types

type ConfirmOption

type ConfirmOption func(*confirmOptions)

ConfirmOption configures the behavior of Confirm.

func WithDefault

func WithDefault(d bool) ConfirmOption

WithDefault sets the default answer when the user presses Enter without input. Defaults to false (No) for safety on destructive operations.

func WithHelp

func WithHelp(help string) ConfirmOption

WithHelp sets optional help text shown when the user presses '?'.

func WithYesFlag

func WithYesFlag(yes bool) ConfirmOption

WithYesFlag sets whether the --yes flag was provided, bypassing the prompt.

type InputOption

type InputOption func(*inputOptions)

InputOption configures the behavior of Input.

func WithInputDefault

func WithInputDefault(d string) InputOption

WithInputDefault sets the default value when the user presses Enter without input.

func WithInputHelp

func WithInputHelp(help string) InputOption

WithInputHelp sets optional help text shown when the user presses '?'.

func WithInputValidate

func WithInputValidate(fn func(string) error) InputOption

WithInputValidate sets a validation function for the input. Return nil if valid, or an error describing the issue.

type MultiSelectOption

type MultiSelectOption func(*multiSelectOptions)

MultiSelectOption configures the behavior of MultiSelect.

func WithMultiSelectDefaults

func WithMultiSelectDefaults(defaults []string) MultiSelectOption

WithMultiSelectDefaults sets the options pre-selected by default.

func WithMultiSelectHelp

func WithMultiSelectHelp(help string) MultiSelectOption

WithMultiSelectHelp sets optional help text shown when the user presses '?'.

func WithMultiSelectPageSize

func WithMultiSelectPageSize(size int) MultiSelectOption

WithMultiSelectPageSize sets how many options are visible at once.

func WithMultiSelectValidate

func WithMultiSelectValidate(fn func([]string) error) MultiSelectOption

WithMultiSelectValidate sets a validation function for the selections.

type PasswordOption

type PasswordOption func(*passwordOptions)

PasswordOption configures the behavior of Password.

func WithPasswordHelp

func WithPasswordHelp(help string) PasswordOption

WithPasswordHelp sets optional help text shown when the user presses '?'.

func WithPasswordValidate

func WithPasswordValidate(fn func(string) error) PasswordOption

WithPasswordValidate sets a validation function for the password. Return nil if valid, or an error describing the issue.

type SelectOption

type SelectOption func(*selectOptions)

SelectOption configures the behavior of Select.

func WithSelectDefault

func WithSelectDefault(d string) SelectOption

WithSelectDefault sets the default selection (must be in the options list).

func WithSelectHelp

func WithSelectHelp(help string) SelectOption

WithSelectHelp sets optional help text shown when the user presses '?'.

func WithSelectPageSize

func WithSelectPageSize(size int) SelectOption

WithSelectPageSize sets how many options are visible at once.

Jump to

Keyboard shortcuts

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