prompt

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2019 License: MIT Imports: 4 Imported by: 0

README

go-prompt

GoDoc Coverage Status Travis CI

A package for prompting the user.

This package contains an interface that should be satisfied by all "prompt agents" and a basic console-based implementation.

Table of Contents

Install

go-prompt is a standard Go module which can be installed with:

go get github.com/ipfs/go-prompt

Usage

Contribute

PRs are welcome!

Small note: If editing the Readme, please conform to the standard-readme specification.

License

MIT © Protocol Labs

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrUserCancel is returned when the user cancels the prompt instead of answering it.
	ErrUserCancel = errors.New("operation canceled by the user")
	// ErrNotSupported is returned by the prompter when it doesn't support some feature.
	ErrNotSupported = errors.New("prompt not supported")
)

Functions

This section is empty.

Types

type ConsolePrompter

type ConsolePrompter struct{}

func Console

func Console() *ConsolePrompter

func (ConsolePrompter) Choose

func (c ConsolePrompter) Choose(message string, choices []string, opts ...Option) (string, error)

func (ConsolePrompter) Password

func (c ConsolePrompter) Password(message string, opts ...Option) (string, error)

func (ConsolePrompter) Prompt

func (c ConsolePrompter) Prompt(message string, opts ...Option) (string, error)

func (ConsolePrompter) YesNo

func (c ConsolePrompter) YesNo(message string, opts ...Option) (bool, error)

type Option

type Option func(opts *options) error

Option is a prompt option.

func Default

func Default(s string) Option

Default sets the default for a prompt.

type Prompter

type Prompter interface {
	// Prompt prompts the user for input.
	Prompt(message string, opts ...Option) (answer string, err error)

	// Password prompts the user for password input.
	Password(message string, opts ...Option) (answer string, err error)

	// YesNo asks the user a yes/no question.
	YesNo(message string, opts ...Option) (answer bool, err error)

	// Choose asks the user to choose from a set of options.
	Choose(message string, options []string, opts ...Option) (choice int, err error)
}

Prompter is the interface satisfied by prompt agents.

Jump to

Keyboard shortcuts

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