ask

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2018 License: Apache-2.0 Imports: 7 Imported by: 4

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 Bool

func Bool(message string) *BoolAsker

Bool returns a BoolAsker that will prompt the user with message when Ask is called.

func Boolf

func Boolf(format string, args ...interface{}) *BoolAsker

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

func (ba *BoolAsker) Ask() (bool, error)

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.

func (*BoolAsker) Default

func (ba *BoolAsker) Default(def bool) *BoolAsker

Default sets the default bool for the BoolAsker. The default bool is returned from Ask if the user entered an empty input.

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 Int

func Int(message string) *IntAsker

Int returns an IntAsker that will prompt the user with message when Ask is called.

func Intf

func Intf(format string, args ...interface{}) *IntAsker

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

func (ia *IntAsker) Ask() (int, error)

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

func (ia *IntAsker) Choices(choices ...int) *IntAsker

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 (*IntAsker) Default

func (ia *IntAsker) Default(def int) *IntAsker

Default sets the default int for the IntAsker. The default int is returned from Ask if the user entered an empty input.

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 Path

func Path(message string) *PathAsker

Path returns a PathAsker that will prompt the user with message when Ask is called.

func Pathf

func Pathf(format string, args ...interface{}) *PathAsker

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

func (pa *PathAsker) Ask() (string, error)

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.

func (*PathAsker) Default

func (pa *PathAsker) Default(def string) *PathAsker

Default sets the default path for the PathAsker. The default path is returned from Ask if the user entered an empty input.

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).

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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