ui

package
v0.1.4308 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2018 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ShouldAskForEndpoint

func ShouldAskForEndpoint(endpoint string, 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, 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(message string) bool

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

func (InteractiveUI) ReadSecretStringFromUser

func (InteractiveUI) ReadSecretStringFromUser(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(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(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(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(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(message string) (string, error)
	ReadStringFromUser(message string, defaultValue string) string
	AskUserToConfirm(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