prompt

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2026 License: Apache-2.0 Imports: 13 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package prompt asks the user for input on stderr and reads the answer from stdin: confirmations, which --force skips, answers, and secrets, which a terminal hides as they are typed. It decides when a command may prompt at all: stdin is a terminal and --non-interactive is not set.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddForceFlag

func AddForceFlag(cmd *cobra.Command)

AddForceFlag adds the --force (-f) flag that skips Confirm.

func AddNonInteractiveFlag

func AddNonInteractiveFlag(cmd *cobra.Command)

AddNonInteractiveFlag adds --non-interactive to a command that prompts for missing required flags.

func AddStdinFlag

func AddStdinFlag(cmd *cobra.Command, name, usage string)

AddStdinFlag adds the bool flag name, which makes the command read a value from stdin, such as --password-stdin. A command given it never prompts, since stdin holds that value.

func CanPrompt

func CanPrompt(cmd *cobra.Command) bool

CanPrompt reports whether the command may prompt for a missing required flag: stdin is a terminal, --non-interactive is not set, and no flag added by AddStdinFlag reads stdin.

func Confirm

func Confirm(cmd *cobra.Command, message string) error

Confirm asks the user to confirm message unless --force is set. The prompt goes to stderr and the answer is read from stdin, so stdout carries only the command's output. Any answer but "y" or "yes" cancels the operation, and so does stdin that holds no answer or cannot be read, with how to skip the confirmation when the command has --force.

func Prompt

func Prompt(cmd *cobra.Command, message string) (string, error)

Prompt writes message to stderr and returns the next line of stdin, trimmed. A later Prompt or Confirm on the same stdin reads the line after it. Stdin ending before an answer cancels the operation, as promptError says.

func PromptSecret

func PromptSecret(cmd *cobra.Command, message string) (string, error)

PromptSecret is Prompt for a secret, such as an API key or a password, which keeps the answer as typed, as trimLineEnding says: when stdin is a terminal, the answer is hidden as it is typed. Ctrl+D, Ctrl+C and the end of input cancel the operation, as promptError says, and leave the terminal as it was; so does a SIGINT or SIGTERM, as exitOnSignal says.

func ReadStdinLine

func ReadStdinLine(cmd *cobra.Command, name, what string) (string, error)

ReadStdinLine returns the first line of stdin, without its line break, for the flag name added by AddStdinFlag, which reads what, such as "password". Stdin without one, or with an empty first line, is a validation error.

func TreatStdinAsTerminalForTesting

func TreatStdinAsTerminalForTesting() (restore func())

TreatStdinAsTerminalForTesting makes CanPrompt treat stdin as a terminal, so a test can answer prompts from a buffer. It returns the function that restores the check.

Types

This section is empty.

Jump to

Keyboard shortcuts

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