Documentation ¶
Overview ¶
Package component defines components that can be made use of in plugins.
Index ¶
- func Ask(q *QuestionConfig, response interface{}) error
- func AskForConfirmation(message string) error
- func BeginsWith(s, prefix string) bool
- func Bold(s string) string
- func Green(s string) string
- func IsTTYEnabled() bool
- func NewAurora() auroraPackage.Aurora
- func NoOnlySpaces(v interface{}) error
- func NoUpperCase(v interface{}) error
- func Prompt(p *PromptConfig, response interface{}, opts ...PromptOpt) error
- func ReadInput(filePath string) ([]byte, error)
- func Rpad(s string, padding int) string
- func Select(p *SelectConfig, response interface{}, opts ...PromptOpt) error
- func StopAllSpinners()
- func TrimRightSpace(s string) string
- func Underline(s string) string
- type OutputType
- type OutputWriter
- func NewObjectWriter(output io.Writer, outputFormat string, data interface{}) OutputWriter
- func NewOutputWriter(output io.Writer, outputFormat string, headers ...string) OutputWriterdeprecated
- func NewOutputWriterWithOptions(output io.Writer, outputFormat string, opts []OutputWriterOption, ...) OutputWriter
- type OutputWriterOption
- type OutputWriterSpinner
- func NewOutputWriterSpinner(opts ...OutputWriterSpinnerOption) OutputWriterSpinner
- func NewOutputWriterSpinnerWithOptions(output io.Writer, outputFormat, spinnerText string, startSpinner bool, ...) (OutputWriterSpinner, error)deprecated
- func NewOutputWriterWithSpinner(output io.Writer, outputFormat, spinnerText string, startSpinner bool, ...) (OutputWriterSpinner, error)deprecated
- type OutputWriterSpinnerOption
- func WithDynamicHeaders(dynamicHeaders ...string) OutputWriterSpinnerOption
- func WithHeaders(headers ...string) OutputWriterSpinnerOption
- func WithOutputFormat(outputFormat OutputType) OutputWriterSpinnerOption
- func WithOutputStream(writer io.Writer) OutputWriterSpinnerOption
- func WithOutputWriterOptions(opts ...OutputWriterOption) OutputWriterSpinnerOption
- func WithSpinnerFinalText(finalText string, prefix log.LogType) OutputWriterSpinnerOption
- func WithSpinnerStarted() OutputWriterSpinnerOption
- func WithSpinnerText(text string) OutputWriterSpinnerOption
- type PromptConfig
- type PromptOpt
- type PromptOptions
- type QuestionConfig
- type SelectConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Ask ¶
func Ask(q *QuestionConfig, response interface{}) error
Ask asks a questions and lets the user select an option.
func AskForConfirmation ¶
AskForConfirmation is used to prompt the user to confirm or deny a choice
func BeginsWith ¶
func IsTTYEnabled ¶
func IsTTYEnabled() bool
func NewAurora ¶
func NewAurora() auroraPackage.Aurora
func NoOnlySpaces ¶ added in v0.90.0
func NoOnlySpaces(v interface{}) error
NoOnlySpaces checks if a given input string contains only empty spaces and returns an error if it does. This function does not panic if the input value is not a string.
func NoUpperCase ¶ added in v0.90.0
func NoUpperCase(v interface{}) error
NoUpperCase checks if a given input string contains uppercase characters and returns an error if it does. This function does not panic if the input value is not a string.
func Prompt ¶
func Prompt(p *PromptConfig, response interface{}, opts ...PromptOpt) error
Prompt for input, reads input value, without trimming any characters (may include leading/tailing spaces)
func Rpad ¶
Rpad adds padding to the right of a string. from https://github.com/spf13/cobra/blob/993cc5372a05240dfd59e3ba952748b36b2cd117/cobra.go#L29
func Select ¶
func Select(p *SelectConfig, response interface{}, opts ...PromptOpt) error
Select an option.
func StopAllSpinners ¶ added in v1.3.0
func StopAllSpinners()
StopAllSpinners stops all running spinners if any
func TrimRightSpace ¶
Types ¶
type OutputType ¶
type OutputType string
OutputType defines the format of the output desired.
const ( // TableOutputType specifies output should be in table format. TableOutputType OutputType = "table" // YAMLOutputType specifies output should be in yaml format. YAMLOutputType OutputType = "yaml" // JSONOutputType specifies output should be in json format. JSONOutputType OutputType = "json" // ListTableOutputType specified output should be in a list table format. ListTableOutputType OutputType = "listtable" )
type OutputWriter ¶
type OutputWriter interface { // SetKeys sets the values to use as the keys for the output values. SetKeys(headerKeys ...string) // MarkDynamicKeys sets the headers as dynamic and only shows the column // if at least one row is non empty for the specified header // Note: This is only supported with output render type TableOutputType MarkDynamicKeys(dynamicKeys ...string) // AddRow appends a new row to our table. AddRow(items ...interface{}) // Render emits the generated table to the output once ready Render() }
OutputWriter is an interface for something that can write output.
func NewObjectWriter ¶
func NewObjectWriter(output io.Writer, outputFormat string, data interface{}) OutputWriter
NewObjectWriter gets a new instance of our output writer.
func NewOutputWriter
deprecated
func NewOutputWriter(output io.Writer, outputFormat string, headers ...string) OutputWriter
NewOutputWriter gets a new instance of our output writer.
Deprecated: NewOutputWriter is being deprecated in favor of NewOutputWriterWithOptions Until it is removed, it will retain the existing behavior of converting incoming row values to their golang string representation for backward compatibility reasons
func NewOutputWriterWithOptions ¶ added in v1.1.0
func NewOutputWriterWithOptions(output io.Writer, outputFormat string, opts []OutputWriterOption, headers ...string) OutputWriter
NewOutputWriterWithOptions gets a new instance of our output writer with some customization options.
type OutputWriterOption ¶ added in v1.1.0
type OutputWriterOption func(*outputwriter)
OutputWriterOption is an option for outputwriter
func WithAutoStringify ¶ added in v1.1.0
func WithAutoStringify() OutputWriterOption
WithAutoStringify configures the output writer to automatically convert row fields to their golang string representations. It is used to maintain backward compatibility with old rendering behavior, and should be _avoided_ if that need does not apply.
type OutputWriterSpinner ¶
type OutputWriterSpinner interface { OutputWriter // RenderWithSpinner will stop spinner and render the output // Deprecated: RenderWithSpinner is being deprecated in favor of Render. RenderWithSpinner() // StartSpinner starts the spinner instance, showing the spinnerText StartSpinner() // StopSpinner stops the running spinner instance, displays FinalText if set StopSpinner() // SetText sets the spinner text SetText(text string) // SetFinalText sets the spinner final text and prefix // log indicator (log.LogTypeOUTPUT can be used for no prefix) SetFinalText(finalText string, prefix log.LogType) }
OutputWriterSpinner is OutputWriter augmented with a spinner.
func NewOutputWriterSpinner ¶ added in v1.2.0
func NewOutputWriterSpinner(opts ...OutputWriterSpinnerOption) OutputWriterSpinner
NewOutputWriterSpinner returns implementation of OutputWriterSpinner
func NewOutputWriterSpinnerWithOptions
deprecated
added in
v1.1.0
func NewOutputWriterSpinnerWithOptions(output io.Writer, outputFormat, spinnerText string, startSpinner bool, opts []OutputWriterOption, headers ...string) (OutputWriterSpinner, error)
NewOutputWriterSpinnerWithOptions returns implementation of OutputWriterSpinner.
Deprecated: NewOutputWriterSpinnerWithOptions is being deprecated in favor of NewOutputWriterSpinner.
func NewOutputWriterWithSpinner
deprecated
func NewOutputWriterWithSpinner(output io.Writer, outputFormat, spinnerText string, startSpinner bool, headers ...string) (OutputWriterSpinner, error)
NewOutputWriterWithSpinner returns implementation of OutputWriterSpinner.
Deprecated: NewOutputWriterWithSpinner is being deprecated in favor of NewOutputWriterSpinner. Until it is removed, it will retain the existing behavior of converting incoming row values to their golang string representation for backward compatibility reasons
type OutputWriterSpinnerOption ¶ added in v1.2.0
type OutputWriterSpinnerOption func(*outputwriterspinner)
OutputWriterSpinnerOption is an option to configure outputwriterspinner
func WithDynamicHeaders ¶ added in v1.3.0
func WithDynamicHeaders(dynamicHeaders ...string) OutputWriterSpinnerOption
WithDynamicHeaders sets the headers as dynamic and only shows the column if at least one row is non empty for the specified header
func WithHeaders ¶ added in v1.2.0
func WithHeaders(headers ...string) OutputWriterSpinnerOption
WithHeaders sets key headers
func WithOutputFormat ¶ added in v1.2.0
func WithOutputFormat(outputFormat OutputType) OutputWriterSpinnerOption
WithOutputFormat sets output format for the OutputWriterSpinner component
func WithOutputStream ¶ added in v1.2.0
func WithOutputStream(writer io.Writer) OutputWriterSpinnerOption
WithOutputStream sets the output stream for the OutputWriterSpinner component
func WithOutputWriterOptions ¶ added in v1.2.0
func WithOutputWriterOptions(opts ...OutputWriterOption) OutputWriterSpinnerOption
WithOutputWriterOptions configures OutputWriterOptions to the spinner
func WithSpinnerFinalText ¶ added in v1.2.0
func WithSpinnerFinalText(finalText string, prefix log.LogType) OutputWriterSpinnerOption
WithSpinnerFinalText sets the spinner final text and prefix log indicator (log.LogTypeOUTPUT can be used for no prefix)
func WithSpinnerStarted ¶ added in v1.2.0
func WithSpinnerStarted() OutputWriterSpinnerOption
WithSpinnerStarted starts the spinner
func WithSpinnerText ¶ added in v1.2.0
func WithSpinnerText(text string) OutputWriterSpinnerOption
WithSpinnerText sets the spinner text
type PromptConfig ¶
type PromptConfig struct { // Message to display to user. Message string // Options for user to choose from Options []string // Default option. Default string // Sensitive information. Sensitive bool // Multiline response Multiline bool // Help for the prompt. Help string }
PromptConfig is the configuration for a prompt.
func (*PromptConfig) Run ¶
func (p *PromptConfig) Run(response interface{}, opts ...PromptOpt) error
Run the prompt.
type PromptOpt ¶
type PromptOpt func(*PromptOptions) error
PromptOpt is an option for prompts
func WithStdio ¶
func WithStdio(in terminal.FileReader, out terminal.FileWriter, err io.Writer) PromptOpt
WithStdio specifies the standard input, output and error. By default, these are os.Stdin, os.Stdout, and os.Stderr.
func WithValidator ¶ added in v0.90.0
func WithValidator(v survey.Validator) PromptOpt
WithValidator specifies a validator to use while prompting the user
type PromptOptions ¶
type PromptOptions struct { // Standard in/out/error Stdio terminal.Stdio Icons survey.IconSet // Validators on user inputs Validators []survey.Validator }
PromptOptions are options for prompting.
type QuestionConfig ¶
type QuestionConfig struct {
Message string
}
QuestionConfig stores config for prompting a CLI question.
func (*QuestionConfig) Run ¶
func (q *QuestionConfig) Run(response interface{}) error
Run asks a question.
type SelectConfig ¶
type SelectConfig struct { // Message to display to user. Message string // Default option. Default interface{} // Options to select frorm. Options []string // Sensitive information. Sensitive bool // Help for the prompt. Help string // PageSize defines how many options per page. PageSize int }
SelectConfig is the configuration for a selection.
func (*SelectConfig) Run ¶
func (p *SelectConfig) Run(response interface{}, opts ...PromptOpt) error
Run the selection.