Help us shape the future of Go! Take the 2026 Go Developer Survey

confirm

package
v1.10.0 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package confirm provides confirmation prompts for destructive operations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Choice added in v0.7.0

type Choice struct {
	Label       string
	Description string
}

Choice represents an option in a multiple choice prompt.

type ChoiceResult added in v0.7.0

type ChoiceResult int

ChoiceResult represents the result of a choice prompt.

const (
	// ChoiceCancelled indicates the user cancelled the prompt.
	ChoiceCancelled ChoiceResult = -1
)

type Prompter

type Prompter struct {
	Stdin  io.Reader
	Stdout io.Writer
	Stderr io.Writer

	// BufReader, when set, is a shared buffered stdin reader used instead of
	// allocating a per-call one. Sharing one reader across prompters (e.g. a
	// passphrase prompt then a confirm prompt) prevents double-buffering: a
	// fresh bufio.Reader over piped stdin would find the bytes already
	// read-ahead into the first reader's buffer and hit EOF.
	BufReader *bufio.Reader

	// Target is a provider-neutral description of where the operation applies
	// (provider.Target.String(), e.g. "profile dev · account 123456789012 ·
	// region us-east-1" for AWS or "project my-project" for Google Cloud). When
	// set, it is shown before the prompt.
	Target string
}

Prompter handles confirmation prompts.

func (*Prompter) Confirm

func (p *Prompter) Confirm(message string, skipConfirm bool) (bool, error)

Confirm displays a confirmation prompt and returns true if the user confirms. If skipConfirm is true, returns true without prompting.

func (*Prompter) ConfirmAction

func (p *Prompter) ConfirmAction(action, target string, skipConfirm bool) (bool, error)

ConfirmAction is a convenience function for confirming an action.

func (*Prompter) ConfirmChoice added in v0.7.0

func (p *Prompter) ConfirmChoice(message string, choices []Choice) (ChoiceResult, error)

ConfirmChoice displays a multiple choice prompt and returns the selected index. Returns ChoiceCancelled (-1) if the user cancels or selects cancel option. The first choice (index 0) is the default when user just presses Enter.

func (*Prompter) ConfirmDelete

func (p *Prompter) ConfirmDelete(target string, skipConfirm bool) (bool, error)

ConfirmDelete confirms a delete operation with a warning.

func (*Prompter) ConfirmRecoverableDelete added in v1.10.0

func (p *Prompter) ConfirmRecoverableDelete(target, recovery string, skipConfirm bool) (bool, error)

ConfirmRecoverableDelete confirms a delete that the backend keeps recoverable (Key Vault soft-delete, a Secrets Manager recovery window). recovery says how it can be recovered and is shown after the target.

Jump to

Keyboard shortcuts

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