Documentation
¶
Index ¶
- func Confirm(f *factory.Factory, prompt string) (bool, error)
- func HasDataAvailable(reader io.Reader) bool
- func Pager(noPager bool) (w io.Writer, cleanup func() error)
- func ProgressBar(completed, total, width int) string
- func ProgressLine(label string, completed, total, succeeded, failed, barWidth int) string
- func PromptForInput(prompt, defaultVal string, noInput bool) (string, error)
- func PromptForOne(resource string, options []string, noInput bool) (string, error)
- func ReadLine() (string, error)
- func ReadPassword() (string, error)
- func SpinWhile(f *factory.Factory, name string, action func()) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Confirm ¶
Confirm prompts the user with a yes/no question. Returns true if the user confirmed, false otherwise.
IMPORTANT: Commands using Confirm() must call f.SetGlobalFlags(cmd) in PreRunE. See factory.SetGlobalFlags() documentation for details.
Usage:
confirmed, err := io.Confirm(f, "Do the thing?")
if err != nil {
return err
}
if confirmed {
// do the thing
}
func HasDataAvailable ¶
HasDataAvailable will return whether the given Reader has data available to read
func Pager ¶ added in v3.17.0
Pager returns a writer hooked up to a pager (default: less -R) when stdout is a TTY. Falls back to stdout when paging is disabled or the pager cannot run.
func ProgressBar ¶ added in v3.17.0
func ProgressLine ¶ added in v3.17.0
func PromptForInput ¶ added in v3.17.0
PromptForInput prompts the user to enter a string value. If a default value is provided, it will be shown in brackets and used if the user presses enter. If noInput is true, it will return the default value or an error if no default is provided.
func PromptForOne ¶
PromptForOne will show the list of options to the user, allowing them to select one to return. It's possible for them to choose none or cancel the selection, resulting in an error. If noInput is true, it will fail instead of prompting. If there's no TTY available, it will also fail instead of prompting.
For global flag support requirements, see the Confirm() function documentation.
func ReadLine ¶ added in v3.14.2
ReadLine reads a line of input from stdin with terminal support. If running in a TTY, it uses x/term for better line editing (backspace, arrows, etc.). If not in a TTY (e.g., piped input), it falls back to bufio.
func ReadPassword ¶ added in v3.14.2
ReadPassword reads a password from stdin without echoing. This is a convenience wrapper around term.ReadPassword.
Types ¶
This section is empty.