Documentation ¶
Overview ¶
Package ask collects information from the user through the command line in a Q&A style.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BoolAsker ¶
type BoolAsker struct {
// contains filtered or unexported fields
}
BoolAsker is an object that can ask for a bool on the command line.
func Boolf ¶
Boolf returns a BoolAsker that will prompt the user with a message according to a format specifier. See the fmt package for formatting rules.
func (*BoolAsker) Ask ¶
Ask prompts the user by displaying the BoolAsker's message, reads from standard input until it encounters a newline or EOF, converts the input to a bool and returns the bool. If the user enters an empty input and a default bool is set, the default int will be returned. Returns an error if stdin could not be read, if the input is too large for memory, or if the input could not be converted to bool.
Case-insensitive inputs "y" and "yes" convert to true, "n" and "no" convert to false.
type FloatAsker ¶
type FloatAsker struct {
// contains filtered or unexported fields
}
FloatAsker is an object that can ask for a float on the command line.
func Float ¶
func Float(message string) *FloatAsker
Float returns an FloatAsker that will prompt the user with message when Ask is called.
func Floatf ¶
func Floatf(format string, args ...interface{}) *FloatAsker
Floatf returns an FloatAsker that will prompt the user with a message according to a format specifier. See the fmt package for formatting rules.
func (*FloatAsker) Ask ¶
func (fa *FloatAsker) Ask() (float64, error)
Ask prompts the user by displaying the FloatAsker's message, reads from standard input until it encounters a newline or EOF, converts the input to a float and returns the float. If the user enters an empty input and a default float is set, the default float will be returned. Returns an error if stdin could not be read, if the input is too large for memory, or if the input could not be converted to memory.
func (*FloatAsker) Choices ¶
func (fa *FloatAsker) Choices(choices ...float64) *FloatAsker
Choices sets an arbitrary number of choices for the user input. The list of choices will be automatically displayed when prompting the user. If the user enters a choice not in the list, Ask will return an error. If the set of available "choices" does not contain the default, behavior is undefined.
func (*FloatAsker) Default ¶
func (fa *FloatAsker) Default(def float64) *FloatAsker
Default sets the default float for the FloatAsker. The default float is returned from Ask if the user entered an empty input.
type IntAsker ¶
type IntAsker struct {
// contains filtered or unexported fields
}
IntAsker is an object that can ask for an int on the command line.
func Intf ¶
Intf returns an IntAsker that will prompt the user with a message according to a format specifier. See the fmt package for formatting rules.
func (*IntAsker) Ask ¶
Ask prompts the user by displaying the IntAsker's message, reads from standard input until it encounters a newline or EOF, converts the input to an int and returns the int. If the user enters an empty input and a default int is set, the default int will be returned. Returns an error if stdin could not be read, if the input is too large for memory, or if the input could not be converted to memory.
func (*IntAsker) Choices ¶
Choices sets an arbitrary number of choices for the user input. The list of choices will be automatically displayed when prompting the user. If the user enters a choice not in the list, Ask will return an error. If the set of available "choices" does not contain the default, behavior is undefined.
type PathAsker ¶
type PathAsker struct {
// contains filtered or unexported fields
}
PathAsker is an object that can ask for a path on the command line.
func Pathf ¶
Pathf returns a PathAsker that will prompt the user with a message according to a format specifier. See the fmt package for formatting rules.
func (*PathAsker) Ask ¶
Ask prompts the user by displaying the PathAsker's message, reads from standard input until it encounters a newline or EOF and returns the input path. If the user enters an empty input and a default path is set, the default path will be returned. The user can auto-complete the path using TAB in the bash style. Returns an error if stdin could not be read, or if the input is too large for memory.
type StringAsker ¶
type StringAsker struct {
// contains filtered or unexported fields
}
StringAsker is an object that can ask for a string on the command line.
func String ¶
func String(message string) *StringAsker
String returns a StringAsker that will prompt the user with message when Ask is called.
func Stringf ¶
func Stringf(format string, args ...interface{}) *StringAsker
Stringf returns a StringAsker that will prompt the user with a message according to a format specifier. See the fmt package for formatting rules.
func (*StringAsker) Ask ¶
func (sa *StringAsker) Ask() (string, error)
Ask prompts the user by displaying the StringAsker's message, reads from standard input until it encounters a newline or EOF and returns the input string. If the user enters an empty input and a default string is set, the default string will be returned. Returns an error if stdin could not be read, or if the input is too large for memory.
func (*StringAsker) Choices ¶
func (sa *StringAsker) Choices(choices ...string) *StringAsker
Choices sets an arbitrary number of choices for the user input. The list of choices will be automatically displayed when prompting the user and choices will be available to auto-completion using TAB in the readline style. If the user enters a choice not in the list, Ask will return an error. If the set of available "choices" does not contain the default, behavior is undefined.
func (*StringAsker) Default ¶
func (sa *StringAsker) Default(def string) *StringAsker
Default sets the default string for the StringAsker. The default string is returned from Ask if the user entered no input. The default value will be automatically displayed when prompting the user. If the default is not in the set of available choices, behavior is undefined (see StringAsker.Choices).