ui

package
v0.1.3667 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2018 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ShouldAskForEndpoint

func ShouldAskForEndpoint(endpoint string, log *logger.Logger, ui UserInterface, defaultValue string) bool

ShouldAskForEndpoint wraps an AskUserToConfirm dialogue only if their endpoint has changed from the default value.

func ShouldAskForToken

func ShouldAskForToken(token string, log *logger.Logger, ui UserInterface) bool

ShouldAskForToken wraps an AskUserToConfirm dialogue only if their token is empty or blank.

Types

type InteractiveUI

type InteractiveUI struct {
}

InteractiveUI implements the UserInterface used by the real program, not in tests.

func (InteractiveUI) AskUserToConfirm

func (InteractiveUI) AskUserToConfirm(_ *logger.Logger, message string) bool

AskUserToConfirm will prompt the user to confirm with the provided message.

func (InteractiveUI) ReadSecretStringFromUser

func (InteractiveUI) ReadSecretStringFromUser(_ *logger.Logger, message string) (string, error)

ReadSecretStringFromUser can be used to read a value from the user by masking their input. It's useful for token input in our case.

func (InteractiveUI) ReadStringFromUser

func (InteractiveUI) ReadStringFromUser(_ *logger.Logger, message string, defaultValue string) string

ReadStringFromUser can be used to read any value from the user or the defaultValue when provided.

type TestingUI

type TestingUI struct {
	Input   string
	Confirm bool
}

TestingUI implements the UserInterface for our testing purposes.

func (TestingUI) AskUserToConfirm

func (ui TestingUI) AskUserToConfirm(log *logger.Logger, message string) bool

AskUserToConfirm works by printing the provided message to standard out and returning a Confirm dialogue up the chain.

func (TestingUI) ReadSecretStringFromUser

func (ui TestingUI) ReadSecretStringFromUser(log *logger.Logger, message string) (string, error)

ReadSecretStringFromUser implements the TestingUI interface for asking a user's input. It works by simply printing the message to standard output and passing the input through.

func (TestingUI) ReadStringFromUser

func (ui TestingUI) ReadStringFromUser(log *logger.Logger, message string, defaultValue string) string

ReadStringFromUser implements the TestingUI interface for asking a user's input. It works by simply printing the message to standard output and passing the input through.

type UserInterface

type UserInterface interface {
	ReadSecretStringFromUser(log *logger.Logger, message string) (string, error)
	ReadStringFromUser(log *logger.Logger, message string, defaultValue string) string
	AskUserToConfirm(log *logger.Logger, message string) bool
}

UserInterface is created to allow us to pass a mock user interface for testing. Since we can't properly run integration tests on code that calls PromptUI. This is because the first call to PromptUI reads from stdin correctly, but subsequent calls return EOF.

Jump to

Keyboard shortcuts

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