Documentation ¶
Overview ¶
Package disgo is a simple library for building Go command-line interfaces.
It does not provide structured logging and is not built with performance in mind, since it is aimed at building user-friendly command line interfaces, and not applications.
Index ¶
- Variables
- func Confirm(config Confirmation) (bool, error)
- func Debug(a ...interface{})
- func Debugf(format string, a ...interface{})
- func Debugln(a ...interface{})
- func DefaultConfirmation(input string) (bool, error)
- func EndStep()
- func Error(a ...interface{})
- func Errorf(format string, a ...interface{})
- func Errorln(a ...interface{})
- func FailStep(err error) error
- func FailStepf(format string, a ...interface{}) error
- func Info(a ...interface{})
- func Infof(format string, a ...interface{})
- func Infoln(a ...interface{})
- func SetTerminalOptions(options ...func(*Terminal))
- func StartStep(label string)
- func StartStepf(format string, a ...interface{})
- func WithColors(enabled bool) func(*Terminal)
- func WithDebug(enabled bool) func(*Terminal)
- func WithDefaultOutput(writer io.Writer) func(*Terminal)
- func WithErrorOutput(writer io.Writer) func(*Terminal)
- func WithInteractive(enabled bool) func(*Terminal)
- func WithReader(reader io.Reader) func(*Terminal)
- type Confirmation
- type ConfirmationParser
- type Terminal
- func (t Terminal) Confirm(config Confirmation) (bool, error)
- func (t Terminal) Debug(a ...interface{})
- func (t Terminal) Debugf(format string, a ...interface{})
- func (t Terminal) Debugln(a ...interface{})
- func (t *Terminal) EndStep()
- func (t Terminal) Error(a ...interface{})
- func (t Terminal) Errorf(format string, a ...interface{})
- func (t Terminal) Errorln(a ...interface{})
- func (t *Terminal) FailStep(err error) error
- func (t *Terminal) FailStepf(format string, a ...interface{}) error
- func (t Terminal) Info(a ...interface{})
- func (t Terminal) Infof(format string, a ...interface{})
- func (t Terminal) Infoln(a ...interface{})
- func (t *Terminal) StartStep(label string)
- func (t *Terminal) StartStepf(format string, a ...interface{})
Constants ¶
This section is empty.
Variables ¶
var ( // DefaultConfirmationChoices is the default value // for the choices that are given to // the users in a confirmation prompt. DefaultConfirmationChoices = []string{"y", "n"} )
Functions ¶
func Confirm ¶
func Confirm(config Confirmation) (bool, error)
Confirm prompts the user to confirm something using the global terminal.
func Debug ¶
func Debug(a ...interface{})
Debug writes a debug output on the global terminal's default writer if the debug outputs are enabled.
func Debugf ¶
func Debugf(format string, a ...interface{})
Debugf formats according to a format specifier and writes to the global terminal's default writer if the debug outputs are enabled.
func Debugln ¶
func Debugln(a ...interface{})
Debugln writes a debug output on the global terminal's default writer if the debug outputs are enabled and appends a newline to its input.
func DefaultConfirmation ¶
DefaultConfirmation is a confirmation parser that covers most cases for confirmation. It converts y/Y/yes/YES/t/T/true/True/1 to true. It converts n/N/no/NO/f/F/false/FALSE/0 to false.
func EndStep ¶
func EndStep()
EndStep ends a step with a success state on the global. terminal. It then prints all of the outputs that were queued while the step was in progress. Warning: This is not thread-safe.
func Error ¶
func Error(a ...interface{})
Error writes an error output on the global terminal's error writer.
func Errorf ¶
func Errorf(format string, a ...interface{})
Errorf formats according to a format specifier and writes to the global terminal's error writer.
func Errorln ¶
func Errorln(a ...interface{})
Errorln writes an error output on the global terminal's error writer. It appends a newline to its input.
func FailStep ¶
FailStep ends a step with a failure state. It then prints all of the outputs that were queued while the step was in progress, and returns the given error for error handling. Warning: This is not thread-safe.
func FailStepf ¶
FailStepf ends a step with a failure state on the global. terminal. It then prints all of the outputs that were queued while the step was in progress, and returns an error created from the given format and arguments. Warning: This is not thread-safe.
func Info ¶
func Info(a ...interface{})
Info writes an info output on the global terminal's default writer.
func Infof ¶
func Infof(format string, a ...interface{})
Infof formats according to a format specifier and writes to the global terminal's default writer.
func Infoln ¶
func Infoln(a ...interface{})
Infoln writes an info output on the global terminal's default writer and appends a newline to its input.
func SetTerminalOptions ¶ added in v0.3.0
func SetTerminalOptions(options ...func(*Terminal))
SetTerminalOptions applies options to the global terminal.
func StartStep ¶
func StartStep(label string)
StartStep sets a step in the global terminal, which prints the step's label and makes the terminal queue outputs until the step is ended or failed. If a step was already in progress, it is considered to have been ended successfully. Warning: This is not thread-safe.
func StartStepf ¶
func StartStepf(format string, a ...interface{})
StartStepf sets a step in the terminal, which prints the step's label and makes the terminal queue outputs until the step is ended or failed. If a step was already in progress, it is considered to have been ended successfully. Warning: This is not thread-safe.
func WithColors ¶
WithColors sets the use of colors in the terminal. By default, whether or not colors are enabled depends on the user's TTY, but this option can be used to force colors to be enabled or disabled.
func WithDefaultOutput ¶
WithDefaultOutput sets the default writer on the terminal.
func WithErrorOutput ¶
WithErrorOutput sets the error writer on the terminal.
func WithInteractive ¶
WithInteractive enables or disables the terminal interactive mode.
func WithReader ¶
WithReader sets the reader on the Terminal. By default, if this option is not used, the default reader will be os.Stdin.
Types ¶
type Confirmation ¶
type Confirmation struct { // The label that will be prompted to the user. // Example: `Are you sure?` Label string // The choices that will be presented to the user. // Example: `Y/n`. (A good practice is to uppercase // the default value, if there is one). Choices []string // EnableDefaultValue tells the terminal whether or not // there is a default value that will be used when the // user doesn't input any data. EnableDefaultValue bool // DefaultValue is the default value that will be used when // the user doesn't input any data, if EnableDefaultValue // is set to true OR that the terminal is set to not // interactive. DefaultValue bool // The parser that will be used to convert the user's input // into a true/false value. Parser ConfirmationParser }
Confirmation represents a confirmation prompt's configuration.
type ConfirmationParser ¶
ConfirmationParser is a function that parses an input and returns a confirmation value as well as an error, if the input can't be parsed.
type Terminal ¶ added in v0.3.0
type Terminal struct {
// contains filtered or unexported fields
}
Terminal represents a disgo Terminal. It can write to and prompt users in a command-line interface.
func NewTerminal ¶ added in v0.3.0
NewTerminal creates a new Terminal.
func (Terminal) Confirm ¶ added in v0.3.0
func (t Terminal) Confirm(config Confirmation) (bool, error)
Confirm prompts the user to confirm something.
func (Terminal) Debug ¶ added in v0.3.0
func (t Terminal) Debug(a ...interface{})
Debug writes a debug output on the terminal's default writer if the debug outputs are enabled.
func (Terminal) Debugf ¶ added in v0.3.0
Debugf formats according to a format specifier and writes to the terminal's default writer if the debug outputs are enabled.
func (Terminal) Debugln ¶ added in v0.3.0
func (t Terminal) Debugln(a ...interface{})
Debugln writes a debug output on the terminal's default writer if the debug outputs are enabled and appends a newline to its input.
func (*Terminal) EndStep ¶ added in v0.3.0
func (t *Terminal) EndStep()
EndStep ends a step with a success state. It then prints all of the outputs that were queued while the step was in progress.
func (Terminal) Error ¶ added in v0.3.0
func (t Terminal) Error(a ...interface{})
Error writes an error output on the terminal's error writer.
func (Terminal) Errorf ¶ added in v0.3.0
Errorf formats according to a format specifier and writes to the terminal's error writer.
func (Terminal) Errorln ¶ added in v0.3.0
func (t Terminal) Errorln(a ...interface{})
Errorln writes an error output on the terminal's error writer. It appends a newline to its input.
func (*Terminal) FailStep ¶ added in v0.3.0
FailStep ends a step with a failure state. It then prints all of the outputs that were queued while the step was in progress, and returns the given error for error handling.
func (*Terminal) FailStepf ¶ added in v0.3.0
FailStepf ends a step with a failure state. It then prints all of the outputs that were queued while the step was in progress, and returns an error created from the given format and arguments.
func (Terminal) Info ¶ added in v0.3.0
func (t Terminal) Info(a ...interface{})
Info writes an info output on the terminal's default writer.
func (Terminal) Infof ¶ added in v0.3.0
Infof formats according to a format specifier and writes to the terminal's default writer.
func (Terminal) Infoln ¶ added in v0.3.0
func (t Terminal) Infoln(a ...interface{})
Infoln writes an info output on the terminal's default writer and appends a newline to its input.
func (*Terminal) StartStep ¶ added in v0.3.0
StartStep sets a step in the terminal, which prints the step's label and makes the terminal queue outputs until the step is ended or failed. If a step was already in progress, it is considered to have been ended successfully.
func (*Terminal) StartStepf ¶ added in v0.3.0
StartStepf sets a step in the terminal, which prints the step's label and makes the terminal queue outputs until the step is ended or failed. If a step was already in progress, it is considered to have been ended successfully.