Documentation ¶
Index ¶
- func EnvColorDisabled() bool
- func EnvColorForced() bool
- func IsTerminal(stream IOStream) bool
- func MatchAny(p Prompt) bool
- type Formatter
- func (f *Formatter) Blue(t string) string
- func (f *Formatter) Bluef(t string, args ...interface{}) string
- func (f *Formatter) Bold(t string) string
- func (f *Formatter) Boldf(t string, args ...interface{}) string
- func (f *Formatter) Color(s string, style string) string
- func (f *Formatter) Cyan(t string) string
- func (f *Formatter) Cyanf(t string, args ...interface{}) string
- func (f *Formatter) Failure(t string) string
- func (f *Formatter) FailureIcon() string
- func (f *Formatter) Gray(t string) string
- func (f *Formatter) Grayf(t string, args ...interface{}) string
- func (f *Formatter) Green(t string) string
- func (f *Formatter) Greenf(t string, args ...interface{}) string
- func (f *Formatter) Info(t string) string
- func (f *Formatter) InfoIcon() string
- func (f *Formatter) Magenta(t string) string
- func (f *Formatter) Magentaf(t string, args ...interface{}) string
- func (f *Formatter) Red(t string) string
- func (f *Formatter) Redf(t string, args ...interface{}) string
- func (f *Formatter) Success(t string) string
- func (f *Formatter) SuccessIcon() string
- func (f *Formatter) Underline(t string) string
- func (f *Formatter) Underlinef(t string, args ...interface{}) string
- func (f *Formatter) Warning(t string) string
- func (f *Formatter) WarningIcon() string
- func (f *Formatter) Yellow(t string) string
- func (f *Formatter) Yellowf(t string, args ...interface{}) string
- type IOStream
- type IOStreams
- func (s *IOStreams) Formatter() *Formatter
- func (s *IOStreams) IsColorEnabled() bool
- func (s *IOStreams) IsInteractive() bool
- func (s *IOStreams) IsStderrTTY() bool
- func (s *IOStreams) IsStdinTTY() bool
- func (s *IOStreams) IsStdoutTTY() bool
- func (s *IOStreams) ProgressIndicator() *ProgressIndicator
- func (s *IOStreams) Prompter() *SurveyPrompter
- func (s *IOStreams) SetColorEnabled(v bool)
- func (s *IOStreams) SetInteractive(v bool)
- func (s *IOStreams) SetStderrTTY(isTTY bool)
- func (s *IOStreams) SetStdinTTY(isTTY bool)
- func (s *IOStreams) SetStdoutTTY(isTTY bool)
- type Matcher
- type ProgressIndicator
- type Prompt
- type PromptOpt
- type PromptParams
- type PromptType
- type Prompter
- type Responder
- type Stub
- type StubPrompter
- func (sp *StubPrompter) Confirm(msg string, value bool, opts ...PromptOpt) (bool, error)
- func (sp *StubPrompter) Input(msg string, value string, opts ...PromptOpt) (string, error)
- func (sp *StubPrompter) MultiSelect(msg string, options []string, values []string, opts ...PromptOpt) ([]string, error)
- func (sp *StubPrompter) RegisterStub(matcher Matcher, responder Responder) *StubPrompter
- func (sp *StubPrompter) Select(msg string, options []string, value string, opts ...PromptOpt) (string, error)
- func (sp *StubPrompter) VerifyStubs(test testable)
- type SurveyPrompter
- func (p *SurveyPrompter) Confirm(msg string, value bool, opts ...PromptOpt) (bool, error)
- func (p *SurveyPrompter) Input(msg string, value string, opts ...PromptOpt) (string, error)
- func (p *SurveyPrompter) MultiSelect(msg string, options []string, values []string, opts ...PromptOpt) ([]string, error)
- func (p *SurveyPrompter) Select(msg string, options []string, value string, opts ...PromptOpt) (string, error)
- type UserInterface
- func (ui *UserInterface) Confirm(msg string, value bool, opts ...PromptOpt) (bool, error)
- func (ui *UserInterface) Err(s string, args ...any)
- func (ui *UserInterface) Input(msg string, value string, opts ...PromptOpt) (string, error)
- func (ui *UserInterface) IsStubbed() bool
- func (ui *UserInterface) MultiSelect(msg string, options []string, values []string, opts ...PromptOpt) ([]string, error)
- func (ui *UserInterface) Out(s string, args ...any)
- func (ui *UserInterface) RegisterStub(matcher Matcher, responder Responder) *UserInterface
- func (ui *UserInterface) Select(msg string, options []string, value string, opts ...PromptOpt) (string, error)
- func (ui *UserInterface) VerifyStubs(t testable)
- func (ui *UserInterface) WithStubbing() *UserInterface
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EnvColorDisabled ¶ added in v0.7.0
func EnvColorDisabled() bool
func EnvColorForced ¶ added in v0.7.0
func EnvColorForced() bool
func IsTerminal ¶ added in v0.7.0
IsTerminal returns true if the stream is a terminal.
Types ¶
type Formatter ¶ added in v0.7.0
type Formatter struct {
// contains filtered or unexported fields
}
Formatter wraps strings in ANSI escape sequences.
func NewFormatter ¶ added in v0.7.0
func (*Formatter) FailureIcon ¶ added in v0.7.0
func (*Formatter) SuccessIcon ¶ added in v0.7.0
func (*Formatter) Underlinef ¶ added in v0.7.0
func (*Formatter) WarningIcon ¶ added in v0.7.0
type IOStreams ¶ added in v0.7.0
type IOStreams struct { // os.Stdin (or mock when unit testing) In IOStream // os.Stdout (or mock when unit testing) Out IOStream // os.Stderr (or mock when unit testing) Err IOStream // contains filtered or unexported fields }
Container for the three main CLI I/O streams.
func NewIOStreams ¶ added in v0.7.0
func NewIOStreams() *IOStreams
NewIOStreams returns the default IOStreams containing os.Stdin, os.Stdout, and os.Stderr.
func NewTestIOStreams ¶ added in v0.7.0
func NewTestIOStreams() *IOStreams
NewTestIOStreams returns an IOStreams with mock in/out/err values for testing.
func (*IOStreams) IsColorEnabled ¶ added in v0.7.0
IsColorEnabled returns true if color output is enabled.
func (*IOStreams) IsInteractive ¶ added in v0.7.0
IsInteractive returns true if running interactively. Will be false if either (a) std in/out is not a TTY, or (b) the user has explicitly requested not to be prompted.
func (*IOStreams) IsStderrTTY ¶ added in v0.7.0
IsStderrTTY returns true if [IOStreams.Err] is a TTY.
func (*IOStreams) IsStdinTTY ¶ added in v0.7.0
IsStdinTTY returns true if [IOStreams.In] is a TTY.
func (*IOStreams) IsStdoutTTY ¶ added in v0.7.0
IsStdoutTTY returns true if [IOStreams.Out] is a TTY.
func (*IOStreams) ProgressIndicator ¶ added in v0.7.0
func (s *IOStreams) ProgressIndicator() *ProgressIndicator
ProgressIndicator returns a new progress indicator.
func (*IOStreams) Prompter ¶ added in v0.7.0
func (s *IOStreams) Prompter() *SurveyPrompter
Prompter returns the default, survey based prompter.
func (*IOStreams) SetColorEnabled ¶ added in v0.7.0
SetColorEnabled sets whether color is enabled.
func (*IOStreams) SetInteractive ¶ added in v0.7.0
SetInteractive explicitly sets whether this is an interactive session.
func (*IOStreams) SetStderrTTY ¶ added in v0.7.0
SetStderrTTY explicitly flags [IOStreams.Err] as a TTY.
func (*IOStreams) SetStdinTTY ¶ added in v0.7.0
SetStdinTTY explicitly flags [IOStreams.In] as a TTY.
func (*IOStreams) SetStdoutTTY ¶ added in v0.7.0
SetStdoutTTY explicitly flags [IOStreams.Out] as a TTY.
type Matcher ¶ added in v0.7.0
Matcher is function that matches prompts.
func MatchConfirm ¶ added in v0.7.0
MatchConfirm returns a matcher that matches confirm prompts.
func MatchInput ¶ added in v0.7.0
MatchInput returns a matcher that matches input prompts.
func MatchMultiSelect ¶ added in v0.7.0
MatchMultiSelect returns a matcher that matches multi-select prompts.
func MatchSelect ¶ added in v0.7.0
MatchSelect returns a matcher that matches select prompts.
type ProgressIndicator ¶ added in v0.7.0
type ProgressIndicator struct {
// contains filtered or unexported fields
}
func NewProgressIndicator ¶ added in v0.7.0
func NewProgressIndicator(ios *IOStreams) *ProgressIndicator
func (*ProgressIndicator) IsEnabled ¶ added in v0.7.0
func (pi *ProgressIndicator) IsEnabled() bool
func (*ProgressIndicator) Start ¶ added in v0.7.0
func (pi *ProgressIndicator) Start()
func (*ProgressIndicator) StartWithLabel ¶ added in v0.7.0
func (pi *ProgressIndicator) StartWithLabel(label string)
func (*ProgressIndicator) Stop ¶ added in v0.7.0
func (pi *ProgressIndicator) Stop()
type Prompt ¶ added in v0.7.0
type Prompt struct { Type PromptType Message string Help string Value any Options any }
type PromptOpt ¶ added in v0.8.0
type PromptOpt func(params *PromptParams)
PromptOpt allows setting optional prompt params.
func WithValidation ¶ added in v0.8.0
WithValidation sets the validation rules for a prompt.
type PromptParams ¶ added in v0.8.0
type PromptParams struct { // Help text to show when the user presses "?". Help string // One or more validation rules to be passed // to [validate.KeyVal]. ValidationRules string }
PromptParams holds optional params for Prompter methods.
func GetPromptParams ¶ added in v0.8.0
func GetPromptParams(opts ...PromptOpt) *PromptParams
GetPromptParams returns the params for the given prompt ops.
type PromptType ¶ added in v0.7.0
type PromptType int
var ( PromptTypeUnknown PromptType = 0 PromptTypeConfirm PromptType = 1 PromptTypeInput PromptType = 2 PromptTypeMultiSelect PromptType = 3 PromptTypeSelect PromptType = 4 )
func (PromptType) String ¶ added in v0.7.0
func (pt PromptType) String() string
type Prompter ¶
type Prompter interface { // Confirm prompts for a boolean yes/no value. Confirm(msg string, value bool, opts ...PromptOpt) (bool, error) // Input prompts for single string value. Input(msg string, value string, opts ...PromptOpt) (string, error) // MultiSelect prompts for a slice of string values w/ a fixed set of options. MultiSelect(msg string, options []string, values []string, opts ...PromptOpt) ([]string, error) // Select prompts for single string value w/ a fixed set of options. Select(msg string, options []string, value string, opts ...PromptOpt) (string, error) }
Prompter is an interface for types that prompt for user input.
type Responder ¶ added in v0.7.0
Responder is a function that returns stubbed prompt responses.
func RespondBool ¶ added in v0.7.0
RespondBool creates a responder that returns the given bool.
func RespondDefault ¶ added in v0.9.0
func RespondDefault() Responder
RespondDefault creates a responder that returns the prompt's default value.
func RespondError ¶ added in v0.7.0
RespondError creates a responder that returns the given error.
func RespondString ¶ added in v0.7.0
RespondString creates a responder that returns the given string.
func RespondStringSlice ¶ added in v0.7.0
RespondStringSlice creates a responder that returns the given slice of strings.
type StubPrompter ¶ added in v0.7.0
type StubPrompter struct {
// contains filtered or unexported fields
}
StubPrompter is an implementation of Prompter that invokes stubbed prompts.
func NewStubPrompter ¶ added in v0.7.0
func NewStubPrompter(ios *IOStreams) *StubPrompter
func (*StubPrompter) MultiSelect ¶ added in v0.7.0
func (sp *StubPrompter) MultiSelect(msg string, options []string, values []string, opts ...PromptOpt) ([]string, error)
MultiSelect prompts for a slice of string values w/ a fixed set of options.
func (*StubPrompter) RegisterStub ¶ added in v0.7.0
func (sp *StubPrompter) RegisterStub(matcher Matcher, responder Responder) *StubPrompter
RegisterStub registers a new stub for the given matcher/responder pair.
func (*StubPrompter) Select ¶ added in v0.7.0
func (sp *StubPrompter) Select(msg string, options []string, value string, opts ...PromptOpt) (string, error)
Select prompts for single string value w/ a fixed set of options.
func (*StubPrompter) VerifyStubs ¶ added in v0.7.0
func (sp *StubPrompter) VerifyStubs(test testable)
VerifyStubs fails the test if there are unmatched stubs.
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(ios *IOStreams) *SurveyPrompter
func (*SurveyPrompter) MultiSelect ¶
func (p *SurveyPrompter) MultiSelect( msg string, options []string, values []string, opts ...PromptOpt, ) ([]string, error)
MultiSelect prompts for a slice of string values w/ a fixed set of options.
type UserInterface ¶ added in v0.7.0
type UserInterface struct { *Formatter ProgressIndicator *ProgressIndicator Prompter Prompter // contains filtered or unexported fields }
UserInterface is a high level abstraction for rendering terminal UIs. It supports stubbing interactive prompts and rendering formatted text to os.Stdout.
func NewUserInterface ¶ added in v0.7.0
func NewUserInterface(ios *IOStreams) *UserInterface
NewUserInterface returns a new UserInterface.
func (*UserInterface) Err ¶ added in v0.7.0
func (ui *UserInterface) Err(s string, args ...any)
func (*UserInterface) IsStubbed ¶ added in v0.7.0
func (ui *UserInterface) IsStubbed() bool
IsStubbed returns true if the executor is configured for stubbing.
func (*UserInterface) MultiSelect ¶ added in v0.7.0
func (ui *UserInterface) MultiSelect(msg string, options []string, values []string, opts ...PromptOpt) ([]string, error)
MultiSelect prompts for a slice of string values w/ a fixed set of options.
func (*UserInterface) Out ¶ added in v0.7.0
func (ui *UserInterface) Out(s string, args ...any)
func (*UserInterface) RegisterStub ¶ added in v0.7.0
func (ui *UserInterface) RegisterStub(matcher Matcher, responder Responder) *UserInterface
RegisterStub registers a new stub for the given matcher/responder pair.
func (*UserInterface) Select ¶ added in v0.7.0
func (ui *UserInterface) Select(msg string, options []string, value string, opts ...PromptOpt) (string, error)
Select prompts for single string value w/ a fixed set of options.
func (*UserInterface) VerifyStubs ¶ added in v0.7.0
func (ui *UserInterface) VerifyStubs(t testable)
VerifyStubs fails the test if there are unmatched stubs.
func (*UserInterface) WithStubbing ¶ added in v0.7.0
func (ui *UserInterface) WithStubbing() *UserInterface
WithStubbing configures stubbing and returns the receiver.