ui

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Dec 26, 2022 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Messenger

type Messenger struct {
	// contains filtered or unexported fields
}

Messenger is a generic logger that prefixes lines with status icons.

func NewMessenger

func NewMessenger(ios *ioutil.IOStreams) *Messenger

NewMessenger returns a new IconLogger.

func (*Messenger) Failure

func (m *Messenger) Failure(line string, args ...any)

Failure prints line to StdOut prefixed with "✖".

func (*Messenger) FailureErr

func (m *Messenger) FailureErr(line string, args ...any)

FailureErr prints line to StdErr prefixed with "✖".

func (*Messenger) FailureTag

func (m *Messenger) FailureTag(tag string, line string, args ...any)

FailureTag prints line to StdOut prefixed with "✖ [tag] ".

func (*Messenger) FailureTagErr

func (m *Messenger) FailureTagErr(tag string, line string, args ...any)

FailureTagErr prints line to StdErr prefixed with "✖ [tag] ".

func (*Messenger) Info

func (m *Messenger) Info(line string, args ...any)

Info prints line to StdOut prefixed with "•".

func (*Messenger) InfoErr

func (m *Messenger) InfoErr(line string, args ...any)

InfoErr prints line to StdErr prefixed with "•".

func (*Messenger) InfoTag

func (m *Messenger) InfoTag(tag string, line string, args ...any)

InfoTag prints line to StdOut prefixed with "• [tag] ".

func (*Messenger) InfoTagErr

func (m *Messenger) InfoTagErr(tag string, line string, args ...any)

InfoTagErr prints line to StdErr prefixed with "• [tag] ".

func (*Messenger) Success

func (m *Messenger) Success(line string, args ...any)

Success prints line to StdOut prefixed with "✓".

func (*Messenger) SuccessErr

func (m *Messenger) SuccessErr(line string, args ...any)

SuccessErr prints line to StdErr prefixed with "✓".

func (*Messenger) SuccessTag

func (m *Messenger) SuccessTag(tag string, line string, args ...any)

SuccessTag prints line to StdOut prefixed with "✓ [tag] ".

func (*Messenger) SuccessTagErr

func (m *Messenger) SuccessTagErr(tag string, line string, args ...any)

SuccessTagErr prints line to StdErr prefixed with "✓ [tag] ".

func (*Messenger) Warning

func (m *Messenger) Warning(line string, args ...any)

Warning prints line to StdOut prefixed with "!".

func (*Messenger) WarningErr

func (m *Messenger) WarningErr(line string, args ...any)

WarningErr prints line to StdErr prefixed with "!".

func (*Messenger) WarningTag

func (m *Messenger) WarningTag(tag string, line string, args ...any)

WarningTag prints line to StdOut prefixed with "! [tag] ".

func (*Messenger) WarningTagErr

func (m *Messenger) WarningTagErr(tag string, line string, args ...any)

WarningTagErr prints line to StdOut prefixed with "! [tag] ".

type Prompter

type Prompter interface {
	// Confirm prompts for a boolean yes/no value.
	Confirm(msg string, value bool, help string) (bool, error)
	// Input prompts for single string value.
	Input(msg string, value string, help string) (string, error)
	// MultiSelect prompts for a slice of string values w/ a fixed set of options.
	MultiSelect(msg string, options []string, values []string, help string) ([]string, error)
	// Select prompts for single string value w/ a fixed set of options.
	Select(msg string, options []string, value string, help string) (string, error)
}

Prompter is an interface for types that prompt for user input.

type PrompterMock added in v0.2.0

type PrompterMock struct {
	// ConfirmFunc mocks the Confirm method.
	ConfirmFunc func(msg string, value bool, help string) (bool, error)

	// InputFunc mocks the Input method.
	InputFunc func(msg string, value string, help string) (string, error)

	// MultiSelectFunc mocks the MultiSelect method.
	MultiSelectFunc func(msg string, options []string, values []string, help string) ([]string, error)

	// SelectFunc mocks the Select method.
	SelectFunc func(msg string, options []string, value string, help string) (string, error)
	// contains filtered or unexported fields
}

PrompterMock is a mock implementation of Prompter.

func TestSomethingThatUsesPrompter(t *testing.T) {

	// make and configure a mocked Prompter
	mockedPrompter := &PrompterMock{
		ConfirmFunc: func(msg string, value bool, help string) (bool, error) {
			panic("mock out the Confirm method")
		},
		InputFunc: func(msg string, value string, help string) (string, error) {
			panic("mock out the Input method")
		},
		MultiSelectFunc: func(msg string, options []string, values []string, help string) ([]string, error) {
			panic("mock out the MultiSelect method")
		},
		SelectFunc: func(msg string, options []string, value string, help string) (string, error) {
			panic("mock out the Select method")
		},
	}

	// use mockedPrompter in code that requires Prompter
	// and then make assertions.

}

func NewPrompterMock added in v0.2.0

func NewPrompterMock() *PrompterMock

NewPrompterMock returns a new mock prompter.

func (*PrompterMock) Confirm added in v0.2.0

func (mock *PrompterMock) Confirm(msg string, value bool, help string) (bool, error)

Confirm calls ConfirmFunc.

func (*PrompterMock) ConfirmCalls added in v0.2.0

func (mock *PrompterMock) ConfirmCalls() []struct {
	Msg   string
	Value bool
	Help  string
}

ConfirmCalls gets all the calls that were made to Confirm. Check the length with:

len(mockedPrompter.ConfirmCalls())

func (*PrompterMock) Input added in v0.2.0

func (mock *PrompterMock) Input(msg string, value string, help string) (string, error)

Input calls InputFunc.

func (*PrompterMock) InputCalls added in v0.2.0

func (mock *PrompterMock) InputCalls() []struct {
	Msg   string
	Value string
	Help  string
}

InputCalls gets all the calls that were made to Input. Check the length with:

len(mockedPrompter.InputCalls())

func (*PrompterMock) MultiSelect added in v0.2.0

func (mock *PrompterMock) MultiSelect(msg string, options []string, values []string, help string) ([]string, error)

MultiSelect calls MultiSelectFunc.

func (*PrompterMock) MultiSelectCalls added in v0.2.0

func (mock *PrompterMock) MultiSelectCalls() []struct {
	Msg     string
	Options []string
	Values  []string
	Help    string
}

MultiSelectCalls gets all the calls that were made to MultiSelect. Check the length with:

len(mockedPrompter.MultiSelectCalls())

func (*PrompterMock) Select added in v0.2.0

func (mock *PrompterMock) Select(msg string, options []string, value string, help string) (string, error)

Select calls SelectFunc.

func (*PrompterMock) SelectCalls added in v0.2.0

func (mock *PrompterMock) SelectCalls() []struct {
	Msg     string
	Options []string
	Value   string
	Help    string
}

SelectCalls gets all the calls that were made to Select. Check the length with:

len(mockedPrompter.SelectCalls())

type SurveyPrompter

type SurveyPrompter struct {
	// contains filtered or unexported fields
}

SurveyPrompter is a light wrapper around the survey(https://github.com/go-survey/survey) library.

func NewSurveyPrompter

func NewSurveyPrompter(in fileReader, out fileWriter, err fileWriter, s session) *SurveyPrompter

func (*SurveyPrompter) Confirm

func (p *SurveyPrompter) Confirm(prompt string, defaultValue bool, help string) (bool, error)

Confirm prompts for a boolean yes/no value.

func (*SurveyPrompter) Input

func (p *SurveyPrompter) Input(prompt string, defaultValue string, help string) (string, error)

Input prompts for single string value.

func (*SurveyPrompter) MultiSelect

func (p *SurveyPrompter) MultiSelect(
	prompt string, options []string, defaultValues []string, help string,
) ([]string, error)

MultiSelect prompts for a slice of string values w/ a fixed set of options.

func (*SurveyPrompter) Select

func (p *SurveyPrompter) Select(
	prompt string, options []string, defaultValue string, help string,
) (string, error)

Select prompts for single string value w/ a fixed set of options.

Jump to

Keyboard shortcuts

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